Hello,
I currently have a WinGrid using a DataTable as the datasource. The DataTable contains records that I retreived from an SQL server via a Stored Procedure. When I refresh(rebind) the WinGrid after refreshing the DataTable any selections or expanded nodes, etc will be lost and the grid layout is reset.
What is the proper way to preserve the layout, selections, and expanded nodes after refreshing the data in the underlying DataTable. The data is view only in the WinGrid and is refreshed from the SQL Server every minute or so.
Any suggestions would be appreciated.
Matt
I am prob wrong about this because I haven't been in WinGrid in a while now but if memory serves the webgrid has a savelayout that might do what you want.
Yes, I am familiar with the save layout, however it doesn't seem to save the state of user selections, example:if the user has grouped on a column and they have row 5 expanded then when I rebind all of the rows are collapsed.
Sorry for this question but don't feel like opening another VS project (have 3 open atm) so "Does it maintain the group by?" if so couldn't you just use a group event to save the state and just reload it after bind (in conjuction with savelayout)? Not the most ideal situtation of course
I am not sure, I was going to try that later on today. I just want to make sure that my method isn't too far from the ideal way of doing a refresh.
Hi,
There's no way to do this. What you are doing with the data must be sending a Reset notification to the grid. This tells the grid to throw away everything and create a whole new set of Rows. Since these new rows are not related to the old rows, the grid cannot maintain any row-level state information.
If you wanted to handle this yourself, you could loop through every row in the grid and store the selected and expanded state of each row, but you can't store the row itself, you would have to base it on some key value in the row. Then you could go back and restore everything afterward.
Of course the best thing to do is - don't reset your data source if you can avoid it.
If you change the data source of the grid, then the layout will be lost because the grid will throw away the layout in favor of the new layout for the new data structure. If you are rebinding the grid to a new data source that has exactly the same structure as the original data source, then you can maintain the layout by first saving it to a stream (using grid.DisplayLayout.Save) and then re-loading the layout after you set the data source.