I am trying to add new column to xamdatagrid on fly. I am getting the column anseright but I can't fill it.
Can someone show me what I am doing wrong.
Here is xml
<igDP:XamDataGrid DataSource="{Binding Path=Container.Columns}" GroupByAreaLocation="None" FieldLayoutInitialized="xamDataGrid_FieldLayoutInitialized" > <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" AutoFitMode="Always" AllowAddNew="False" /> </igDP:XamDataGrid.FieldLayoutSettings> </igDP:XamDataGrid>
C# code
public partial class SpreadsheetView : Window { public SpreadsheetView() { InitializeComponent(); } public SpreadsheetViewModel ViewModel { get { return this.DataContext as SpreadsheetViewModel; } } void xamDataGrid_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e) { List<ISimulatedValue> container = this.ViewModel.Container.Columns; for (int i = 0; i < container.Count; i++) { var field = new UnboundField { Name = container[i].Name, BindingMode = BindingMode.TwoWay, BindingPath = new PropertyPath(String.Format("{0}[{1}]", nameof(ISimulatedValue.AllValues), i)), AllowEdit = false, Format = "P2" }; field.Settings.EditAsType = typeof(String); e.FieldLayout.Fields.Add(field); } } }
I got the colum names right, but I can't fill them.
ISimulatedValues.AllValues returns double array
Hello,
Thank you for the clarification.
Please take a quick look at this forum post for information on the recommended way to set the grid's orientation.
https://ko.infragistics.com/community/forums/f/ultimate-ui-for-wpf/92002/columns-vs-rows
As for the amount of rows being shown, this is due to only creating two fields (columns.Count = 2).
Please see my new attached sample below that checks for the length of columns you should create and implements the horizontal orientation as mentioned in the forum thread.
Let me know if I may be of further assistance.
8117.XamDataGrid_AddColumn_modified.zip
public class Values : ISimulatedValue { public Values(string name, double[] vals) { Name = name; AllValues = vals; } public string Name { get; set; } public double[] AllValues { get; set; } }
What I want basicall is, I want to create a data grid, which the column names are the Name property of the class,
and that column filled with numbers from all values
-------------------------------
| Bob | Tom | Lou | Guy|
| 5| 1| 1| 2|
| 4| 4| 3| 2|
| | 2| | 3|
The data set you create is the saeme as I have. I want to add columns as name, and fill the column from Allvalues.
Here is the picture from debugger. As you can see I have 15 double values in AllValues array, but is filling with only first two. I think
my binding is wrong.
Thank you for posting in our forums!
I am having some trouble understanding the issue exactly. Using the code you provided, I am able to fill out data in the grid.
I did realize that you are binding the XamDataGrid to the same collection you are creating columns with.
Perhaps, your data is not formatted correctly. Please see the attached sample and let me know what I am misunderstanding. Feel free to modify this sample or provide your own sample that better demonstrates this issue for me.
XamDataGrid_AddColumn.zip