I am developing an application which requires to populate xamdatagrid dynamically. My concern is to generate the columns dynamically and then adding the rows.
I am having a boolean list "List<bool> IsCombo" of length same as number of columns and true indicates that particular indexed column is combofield and false indicates normal text field. "List<string> Headers" indicating the header of which indicates the headers of the columns and also "List < List<string> > data" which is of length x where x is number of true in IsCombo list, and it indicates the items to bound with specific comboeditor.
I want to do this in C# as it is generated dynamically multiple times.
Please help me do this.
Thanking you in anticipation.
Hello Doshi,
Thank you for choosing Infragistics.
I have been looking into your issue and I have prepared a sample application for you to test if the desired effect is achieved.
In order to achieve the behavior you have described, an approach I can suggest you is to initially create an empty collection of custom DataItem instances that do not introduce any kind of fields and properties because at that moment we do not know what kind of data will be populating the XamDataGrid.
I have created a method called GenerateData, which I use to initialize the data for each of the Lists you have described. I have also created a Button instance and I have handled it's Click event. Inside the event I have created a collection with Styles that target the XamComboEditor. By iterating through each of the strings that represent the headers I create new Field instances and set their properties respectively depending on whether the Field's cells should contain a XamComboEditor or not.
At the end of the iteration I add the current Field to the Fields collection of the initial FieldLayout. Afterwards I add a few blank DataItems to the DataSource of the XamDataGrid and by iterating through the DataRecords, I have set their cell values respectively.
Please note that creating the data as you have described may lead to creating a lot of Styles since the XamComboEditor for each Field is unique based on it's ItemsSource.
If you require any further assistance on this matter, please do not hesitate to ask.
Hi Tacho,
Thank you for the quick reply. I am not able to put the incorporate the code you have provided in my application. I am getting error in the code. In the file MainWindow.xaml.cs, line No. 85, while incorporating this line to my application, it is not able find any property named as AllowEdit. One property called AllowEditResolved is there, but still it is not helping.
Please help me solve the issue.
I am using Visual Studio 2010, if that helps.
As I'm able to resolve the error mentioned in previous post, I tried to remove that line. But there is one more problem with that. I am getting runtime exception of "Index out of range" on the line grid.FieldLayouts[0].Fields.Add(field); On debugging, I came to know that FieldLayouts is empty list. I'm not able to solve the problem.
Please help me solve it.
I was looking exactly for this implementation where I had to create the XamComboEditor at run time based on the Datagrid's datasource. Even had to set the items source of drop down at run time. Was banging my head for one day how to do this and finally got here. It was a life saver :). Thank you so much.