I'm creating a xamDataGrid that groups by a name column. This works perfectly, but the sort order on the group headers seems to be alphabetical and applying a sort order by the date column only sorts the rows within the groups, it doesn't re-order the group headers themselves into date order.
Is there any way to do this or am I heading down a dead-end?
Rob,
Another option is to save the default comparer using GroupByComparerResolved. For example if you have a checkbox that is used for switching between the default comparer and the custom GroupByRecordCountComparer then you can use the following snippet:
public partial class Window1 : Window{ public IComparer defaultComparer; public Window1() { InitializeComponent(); Loaded += new RoutedEventHandler(Window1_Loaded); } void Window1_Loaded(object sender, RoutedEventArgs e) { .... defaultComparer = xamDataGrid1.FieldLayouts[0].Fields[0].GroupByComparerResolved; } private void check_Checked(object sender, RoutedEventArgs e) { xamDataGrid1.FieldLayouts[0].Fields[1].Settings.GroupByComparer = new GroupByRecordCountComparer(); } private void check_Unchecked(object sender, RoutedEventArgs e) { xamDataGrid1.FieldLayouts[0].Fields[1].Settings.GroupByComparer = defaultComparer; }}
Best regards,
Vlad
I've put together a work around, where I go through the SortedFields collection of the FieldLayout for the grid, and store each of the fields in a list. Then clear the SortedFields collection, and go through re-adding the fields from the list.
This causes the grid to update its display and allows me to change the sort type on the fly.
Unfortunately, that still doesn't seem to reset the sort type. Does the grid somehow cache the sort order or something?
Hi Rob,
In this case you can try with the ClearValue method:
xamDataGrid1.FieldLayouts[0].Fields[1].Settings.ClearValue(FieldSettings.GroupByComparerProperty);
Best regards
Thanks for that, the group by count comparer works a treat! One thing though, I'm setting the GrouByComparer property programatically when a user selects the option to sort in this way, but when they deselect the option, and I set the GroupByComparer back to null, it doesn't reset to alphabetical sorting, the count sort remains. Is there another way to do this?
Cheers!