I am implementing grouping in WPF datagrid. I want to sort the grouped items. For example datagrid is having four columns(empno,name,dept,address). I am doing grouping by de
I found that turning on Live Sorting makes the second sort column actually take affect, e.g:
collection.IsLiveSortingRequested = true;
collection.LiveSortingProperties.Clear();
collection.LiveSortingProperties.Add("Contact");
Have you seen the MSDN article How to: Sort a GridView Column When a Header Is Clicked which refers to the sample from ListView That Sorts Data Sample and the latter has (Download sample) link
Funny but the eventual reference to sample download is available only through .NET 3.0 and 3.5 version of the MSDN article but not through versions for .NET 4.0 and 4.5 though the code snippets are the same.
There are also bog articles with samples based on above MSDN sample:
There is also MSDN blog articles with runnable Visual Studio project (with depemnency on WPF Toolkit) :
You can use this code (limitation : the "Country" order will reset to ascending when sorting on "Contact") :
void dgData_Sorting(object sender, DataGridSortingEventArgs e)
{
// reset sortings
collection.SortDescriptions.Clear();
// define column sort
e.Column.SortDirection = e.Column.SortDirection
== ListSortDirection.Ascending
? ListSortDirection.Descending : ListSortDirection.Ascending;
// sort collection
collection.SortDescriptions.Add
(new SortDescription
(e.Column.SortMemberPath
, e.Column.SortDirection.GetValueOrDefault()
)
);
// mark event as handled otherwise the datagrid will "reset" your custom sorting
e.Handled = true;
}