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
715
Field Chooser, Save customization and dynamic columns
posted

Hello,

i use a xamDataGrid with a SQL Data Binding to the DataSource and the autoGenerateFields is set to true.

In my application, the end user can save the layout of the xamdatagrid with the Savecustomization method. It work very fine but when the underlying SQL statement change (ie. add column or remove column), the loadCustomization don't work anymore.

How i can handle this in order to persist the layout?

Helps will be appreciated,

Thanks,

Pierre

Parents Reply
  • 34810
    Verified Answer
    Offline posted in reply to BUI Pierre

    Hello Pierre,

    I would like you to take a look at the following forum thread, where an issue very similar to this one has recently been discussed: http://ko.infragistics.com/community/forums/t/50173.aspx.

    Essentially, the bits to take from this forum thread is that the SaveCustomizations and LoadCustomizations methods are designed to handle end user customizations to the XamDataGrid. By default, removal of a column is not something that an end user can do by default, and so as soon as a column is removed, the LoadCustomizations will not work, because there exists a Field in the saved layout that the XamDataGrid no longer knows about. You are correct in that when doing the addition of columns, the LoadCustomizations works. I was clearly mistaken on that part of my initial response, but this works because the columns that are saved in the SaveCustomizations method still exist when you go to load your customizations.

    My recommendation for you on this matter is to keep track of whether or not the columns collection in your XamDataGrid changes in the way that a column is removed when you load a new SQL statement-driven data table into your XamDataGrid. You could do this by keeping a List<string> and keeping track of the column names in your data table. This would work because since you are auto-generating the fields in your grid, the XamDataGrid will create a field for every column that exists in the bound data table's view. If all of the columns exist for each of the names in your List<string> when you have loaded in your new SQL statement, the LoadCustomizations method should work, assuming the FieldLayoutInitialized event of the XamDataGrid did not fire, because that will mean the XamDataGrid created a new FieldLayout for your fields, which is likely happening when you remove the column from your grid, as well.

    If the column names do not match, then the LoadCustomizations method will not work for you here. In this case, I would recommend that you use the XmlDocument class to read in the file you are saving to and recursively parse it to get your customizations loaded into the grid. This file will contain all of the information about your fields that you need, such as the row and column that the field exists in. By getting this information by parsing your saved file, you can get the Fields in your XamDataGrid by going through the XamDataGrid.FieldLayouts[field layout index].Fields collection and assigning a new ActualPosition to those Fields. This property takes a FieldPosition object, and you can use its constructor to specify the row and column that you wish that field to show up at. Note, that this will still not work for the columns that have been removed, though, as there will not be a column in the bound data source of the XamDataGrid that corresponds to that particular field.

    If you would like to see the LoadCustomizations method in the XamDataGrid work when fields have been removed from the grid, I would suggest that you place a new product idea for it at http://ideas.infragistics.com. This site places you in direct communication with our product management teams who plan and prioritize new features and products based on community and user feedback.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

Children