Link to home
Start Free TrialLog in
Avatar of glopezz
glopezzFlag for Mexico

asked on

How to keep sort state on datagrid after refresh

Hi Experts!

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.

Thanks!!

glopezz
Avatar of willbdman
willbdman
Flag of Australia image

I have an idea, but firstly how are you sorting your datagrid?
ASKER CERTIFIED SOLUTION
Avatar of willbdman
willbdman
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of glopezz

ASKER

Thanks willbdman, I am testing this right now. How about the current sort? Is it possible to maintain it?

Thanks
Avatar of glopezz

ASKER

OK, saving the row sub works fine, however although the small "arrow" of the selected index is positioned where it shoud, the entire row is not "highlighted" as it was originally. Is there a way to highlight it?

Thanks
I'm not sure with that one....

only thin i could think of would be to change the selection background colour:-

Me.DataGrid1.SelectionBackColor = Color.Blue

however, this would cause problems with other selected rows.
What about the answer I gave?
He uses the first answer I Gave