David Brunelle
David Brunelle

Reputation: 6450

WPF Keep column sorting with Datagrid

I have several datagrid where I need to update the informations. Things is, since more than one person works on the system at the same time, the datagrid need to be refreshed on a regular basis. When I refresh, I lose the sorting that user had.

Is there a way to keep it?

thanks

Upvotes: 2

Views: 2244

Answers (2)

Ray Burns
Ray Burns

Reputation: 62939

Just update the contents of the bound collection - don't replace the collection itself. Then you will not get a new CollectionView so your sorting won't be affected.

Upvotes: 5

StrayPointer
StrayPointer

Reputation: 1304

Note that this is untested, but could you do something like this?

ListCollectionView lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(myDataGrid.ItemsSource);
IComparer mySort = lcv.CustomSort;  // assumes you've already set it beforehand
... // stuff happens
lcv.CustomSort = mySort;

I am still learning WPF myself, but hope this is some help... -Matt.

Upvotes: 2

Related Questions