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.
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.
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
Are you sure? I haven't tested this, but I would assume that setting the DataSource on the BindingSource sends a Reset notificaiton which would cause the grid to fire the InitializeLayout event.
I could be wrong. If I am, then once again, there's no event in the grid you can use. Perhaps you could trap some event of the BindingSource itself?
I am facing similar problem , I want to reflect the changes in datasource to the grid ,but unless i bind the grid again i don't see the changes.I want to avoid rebinding basically to preserve the layout. is there anyway where i dont ned to rebing and still see grid reflecting changes !
If you are binding the grid to a data source that is not sending notifications that data has changed, then you need to call grid.Rows.Refresh(ReloadData) to get the grid to pick up the changes.