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 have a binding source object which the grid is bound to and I am setting its DataSource property which will automatically refresh the grid's data. In order for InitializeLayout to be called at each refresh, I would also have to set the grid's DataSource property to the binding source object, otherwise the InitializeLayout is only being called once.
E
You could use the InitializeLayout event of the grid to restore the layout.
There's no event of that grid that will fire before the Data Source is changed, of course. So you will need to save the layout wherever you are changing the data source in your code.
Hi,
Which event would be best to perform this action. I tried BindingContextChanged but it seems to only execute only the first time (the layout of the binding source doesn't change. Here's what I want to do:
- An action is performed to refresh the data
- Before refresh, I save the state of the group by rows to a list
- The binding source of the grid is set and the data is refreshed
- After the refresh, I restore the state of the group by rows that are a part of the list
I would like to keep all of these operations in a UltraWinGrid component that I created used in all screens.
Thanks
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.