I am trying to export the settings of a grid to an XML file. I used grid.DisplayLayout.SaveAsXML. However it was not exporting everything. When I used the grid.DisplayLayout.LoadFromXML to restore the settings, it just doesn't look the same.
Is there any other ways to do what I want? Thanks.
Hi,
Can you be more specific? What exactly do you want to save that is not being saved?
The Save/Load methods on the layout only save column- and band-level properties. The grid will never save anything related to the rows or the data, because that would mean copying the data along with it which would be a huge waste of hard drive space and wouldn't work, anyway, since the data might change the next time the application is run.
I will post two screen shots. One is how the grid originally looks like and I save the layout at that time, and the second is when I load the layout immediately after I save it, so you can tell the difference.
Did you forget to post the screen shots? Or did you figure it out? :)
Sry~ typed in the wrong url...
Before
After
As far as I can tell, It didn't export the AutoFilt Style, and it lost all the heading setting (Display text etc.)
Thanks.
It does not appear that the grid's data source is the same in the second screen shot. It's hard to tell, because the column headers are clipped in the second image, but none of the headers seem to match up to the headers in the first screen shot.
The Layout is schema-specific. This means you can only load a layout into a grid that is using exactly the same schema for which the layout was saved. If you are trying to change the grid's data source to something completely different from the original schema, then you will not be able to load a layout saved with a different schema.
SaveLayout and LoadLayout are really intended to allow you to save user-customizable settings such as the position and width of columns, sorting, filters, etc.
If you want to save settings that are not really user-customizable, such as AutoFitStyle or the display of the Filter Row, then you might want to consider using a Preset, instead of a Layout. To save and load presets at run-time, you would use the PresetSerializer class.
As a matter of fact, the data source is the same as the one before the layout is saved. The reason why it doesn't looks the same is because in the 1st screen shot, the header of each column has a display name and in the 2nd screen shot, these settings lost and it is displaying the original header of the data table in the data source.
I found the problem. When I saved the layout, I mistakenly used another grid, so the layout saved is not of the same grid to be restored. That's why all header settings are lost.