The WPF DataGrid has a default behavior of allowing multicolumn sorts when the user shift-clicks on multiple column headers. Is there a way to change this behavior so that the Shift key is not required? I have already handled the sorting event on the datagrid so that each column will cycle between the three sorting states (Ascending, Descending, and No Sort) and this is all working as expected as long as the shift key is held down, but I would like to make it so that the DataGrid does not reset the sorting on all other columns if the user clicks a column header to add a sort without pressing shift.
I have found a solution that seems to be a bit of a hack, but it works. This article got me pointed in the right direction: http://blogs.msdn.com/b/vinsibal/archive/2008/08/29/wpf-datagrid-tri-state-sorting-sample.aspx?PageIndex=2. That brought me to the understanding the the SortDirection of each column is not really tied to the ItemsSource SortDescriptions in any way. So what I did was subscribe to the Sorting event of the Datagrid and reset the SortDirection of each column that is referenced in the ItemsSource SortDescriptions collection. Apparently, not pressing shift clears the sortdirection of each column, but doesn't reset the SortDescriptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With