How to keep the sort order after grouping in RadGridView
Environment
Product Version | Product | Author |
---|---|---|
2020.3.915 | RadGridView for WinForms | Nadya Karaivanova |
Description
By default, when you perform grouping, RadGridView sorts the created group rows alphabetically. A common requirement is to sort the groups by other criteria which is possible by creating a custom GroupComparer.
Let's say you have a list of emplyees displayed in RadGridView and you sort them by age descending in a way that the oldest employee is on top of the grid.
Then, after grouping you should excpect the group with the oldest employee to be on top again. In this article I will demonstrate how you can sort the groups in a way to keep the group with oldest employee on top.
Solution
It is necessary to create a class that implements the IComparer interface. In the Compare method, you have access to the groups and to the cells that contain the ages in each group. Thus, you can compare the groups by age and order them descending so the oldest emplyoee's group to be on top.