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.
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
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.
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.
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 !
I am binding to LINQ entities, not to a datatable.
What you are trying to achieve can be done by creating a new datatable in memory and then merge that new datatable with the one binded to the grid. Look up datatable.merge. This will not reset the grid.
You should be able to call .Rows.Refresh(RefreshRow.ReloadData); method from the grid. I got this to work smoothly in one project, but having issues with it on another, not sure if it is the enterprise library or the control itself.
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?