Hi,
I am using ultragrid group by feature. When I am using the code following:
ultragrid.DisplayLayout.Bands[0].SortedColumns.Add("Fruit", false, true);
The fruit column will be grouped by category e.g Apple, Banana, Peach in alphabetical order.
However, what if I do not want the group by rows order by alphabetical, but order by a specific rule that I am giving? e.g I want the order like Peach,Apple,Banana.
Thanks,
Xin
Xin,
To do this, you would need to write a class that implements the IComparer interface and assign an instance of that class to the Fruit column's GroupByComparer property. A similar approach can be taken for non-groupby rows by assigning this comparer to the SortComparer property of the column.
-Matt
Just an FYI - if you want the fruits to always sort in the same order, then you only need to use the SortComparer and not the GroupByComparer. You only need the GroupByComparer if you want the GroupByRows to sort a different way than the actual rows.
Thanks for the quick reply.
What do you mean by GroupByRows to sort a different way than the actuall rows? You mean the child rows inside a group?
I want the frutes to be sorted in different order each time when the form pop out according to a specific index number I am giving.
Hi Xin,
Okay... let's take a step back for a second and talk about how grouping works in the grid.
Let's say you have a column in the grid that contains one of three values: High, Medium, and Low. By default, if you sort this column, it will be sorted alphabetically:
High
Low
Medium
When you group by a column, the grid will sort that columns data, then loop through the rows and look for values that are the same. So the groups would end up in the same order as the sorted values.
So, in a case like this, you would probably want to use a SortComparer on the column so the values are sorted like this:
This would have the affect of changing the sort order for both the values in the column and also the groups.
The only time you need a GroupByComparer is if you want to sort the ungrouped values in one order and the grouped rows in a different order.
Ahh , that makes sense, thanks Mike.