Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
45
XamComboEditor as a column in XamDataGrid
posted

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.

Parents
No Data
Reply
  • 6365
    Offline posted

    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.

    XamDataGrid_dynamicFields.zip
Children