Prevent DataGridView from resorting when its DataSource is updated
Posted on 2010-01-06
I have a DataGridView which is bound to an underlying DataTable, which I am able to sort by clicking on the column headers.
However every minute I need to update the DataTable (values in the columns change, but no rows are added/deleted).
When I rebind the DataTable to the DataGridView.DataSource the grid get's unsorted.
(I've tried just updating the DataTable and tried using a BindingSource but the problem seems to be the same)
In the end the only way I was able to do it was to make a note of the last column to be sorted and the direction and then reapply this once the data has been refreshed.
Is there a cleaner way to preserve the sort order when the underlying data is refreshed?