I have a grid that is filled each time the form receives the focus. What happens is that this re-fill the grid I lose what i did before losing focus. How to save the grouping ?
Resetting the data source every time the form gets focus is not a good idea. You will lose all state information such as the activerow, the selected rows, any changes to positions or sizing of the rows and columns, etc.
My advice would be to avoid setting the DataSource on the grid or doing anything that might cause your data source to send a Reset notification if you possibly can.
But, if you want to try to save and restore the grid setting, you can use the Save and Load methods on the grid's DisplayLayout. These settings will only include band and column information, not any row-specific settings.
I'm saving the form below:Dim configGrade As SortedColumnsCollectionconfigGrade = Me.appGrid.DisplayLayout.Bands(0).SortedColumns
How can I do to recover after
That will not work. You cannot set the SortedColumns collection, and even if you could, the code you have here is simply holding a reference to the existing collection.
You have to use the Save and Load methods on the DisplayLayout, as I stated in my earlier post.
Are you saving and loading into the same grid using the same data source?
Are you specifying the categories to save and load?
There's no reason why the save and load methods should not work, unless the band and column structure you are using is not the same between the save and the load, or you are excluding the Columns or SortedColumns from the categories.
Or maybe you are doing something after you load the layout that is causing it to be reset.
The problem is that I save and load normally, the error is that the columns that are grouped when I saved are not regrouped when I load the xml.