In C#, is there a way to determine which FieldLayout is being used without having to loop through all the FieldLayouts[] and comparing with the DefaultFieldLayout?
Hello Jason,
The old FieldLayout is preserved in order to improve performance if the user/developer decides to reset back to the old DataSource in which case the old FieldLayout will be used again and no new FieldLayout will have to be created.The by-design behavior of the XamDataGrid when resetting the DataSource is to create a new FieldLayout if the old one cannot be used for the new DataSource. This is why when creating a new DataTable with an extra column causes the XamDataGrid to create a new FieldLayout.
In order to access the FieldLayout of the current DataSource, you can simply use the DefaultFieldLayout property of the XamDataGrid. (no searching is necessary)In order to remove the old FieldLayouts and avoid the existence of multiple FieldLayouts, you can invoke the Clear method of the FieldLayouts collection prior to resetting the DataSource.
So I have a DataGrid bound to a DataTable and initially there is only one FieldLayout entry in the FieldLayouts array. Through different events(a button click for example) I create a new Datatable but now with an extra column. After binding, I noticed a new FieldLayout entry which contains an extra Field is added to accommodate for the new column. I would like to set that column to read only and I am doing that by setting the AllowEdit flag to false. The problem is determining which Field or FieldLayout to adjust.
Thanks for your help
The DefaultFieldLayout is set by default to the FieldLayout that is associated with the first DataRecord encountered.
There is no particular process that is running for a single FieldLayout at a time. Would you please provide me with more detailed information on what you are referring to by saying "which FieldLayout is being used"?
Having this information will help me further investigate this matter for you.