How to keep sort state on datagrid after refresh
Posted on 2006-06-07
I am using a Windows Forms datagrid, that shows data that is brought from a remote Web Service in xml, then converted to a dataset. Once I have the dataset, I use one of the tables as my datagrid's data source.
The process of bringing the data occurs every 5 seconds, so I fetch the data and refresh the datagrid every 5 seconds using a timer to get the data displayed.
This is what happens every 5 seconds:
1- Get xml from web service
2- Convert xml into dataset
3- Use one of the dataset's tables as the datagrid datasource (DataGrid1.DataSource = dataSet1.Tables(0)
4- Refresh the datagrid (DataGrid1.refresh)
The problem is that I need the current sorting to be kept even after the new data is feteched and the data grid is refreshed. I also lose the selected row. Is there a way to keep the data sorted after refreshing the grid? Keeping the current selected row would be very useful too.