I have a grid with several columns: ParentId, Name, etc....
ParentId is an integer and can be null. If it's not null it will be some positive integer.I wanted to group rows by this ParentId, however if a row's ParentId is null then it should show up in a group by itself instead of grouped to all other rows with a null ParentId.
To do this was relativley easy with IGroupByEvaluator or IGroupByEvaluatorEx. I group the rows and if a row's ParentId is null then I use a group id = -1 X ListIndex. To me this seems pretty resonable given the assumptions and it works fine.
Also I want to trick things a bit so that ParentId is never displayed in the Group text, so I use the InitializeGroupByRow event of the grid to set the grid's DescriptionText to be equal to the Name cell text of the first row in the group. This seems fine too.
The problem comes about because I want the groups sorted on their Description text (or more specifically the Name text from the first row in the group). In other word I first want to group by this ParentID with my special logic, and then have it sort these groups by a cell value (Name) of the first row in the group.
I tried implimenting IGroupByRowEx.Compare and added the special compare logic to lookup the respective Name of the first row in each group being compared. This causes things to be sorted in correct order on screen but it seems to cause the grouping to leave out certain rows from the group dependinding on the initial order of the rows and the groups.
It looks to me like the IGroupByRowEx.Compare aids in the grouping as well as detemining the overal sort order of the groups. Is there anyway to separate these to suite my requirement?
1. Group by ParentID (with special logic).
2. Order GroupByRows by Name (of first row in group).
Thanks much,Gary
Hi Gary,
What exactly is IGroupByRowEx.Compare? I'm not familiar with the IGroupByRowEx interface. So I assume that IGroupByRowEx is the name of your class that implement IComparer?
It seems to me that you need to create an IComparer and assign it to the GroupByComparer property of the ParentID column and that this comparer should handle sorting the GroupByRows based on the Name of the first child row.
I can't see any reason why this would cause rows to be missing from the group. My only guess here is that maybe you assigned your comparer to the SortComparer of the column instead of the GroupByComparer.
From the infragistics documentation: "If your grouping logic requires that it be inconsistent with how the rows are sorted, then you need to implement IGroupByEvaluatorEx interface. IGroupByEvaluatorEx interface lets you supply logic for sorting rows for grouping purposes."
I was just guessing I need to use that because I wanted a different sort for group by rows. I have tried the Sort on the column and that didn't seem to work. I haven't tried the GroupByComparer so I'll do that. I figured that would have the same effect as the IGroupByEvaluatorEx.Compare?
Thanks again.
Implimenting a comparer that compares the GroupByRow's Description worked when I assigned it to the column's GroupByComparer.
Thanks much!
Glad you got it working.
I am aware of IGroupByEvaluator but IGroupByEvaluatorEx is new to me. :)
It looks like the IGroupByEvaluatorEx interface is the same as IGroupByEvaluator, except that it has a Compare method on it.
This Comparer is used for sorting the actual grid rows BEFORE the grouping takes place. It essentially just like the SortCompaer on the column. It looks like this was added in order to support groupings that don't neccessary follow the normal sort order of the column. For example, if you are grouping on the first letter of the text of a cell, you don't neccessary want the rows to be sorted by the entire text.
So the sorted of the rows essentially looks at the IGroupByEvaluatorEx first (if the rows are grouped). Then the SortComparer on the column.
Once the rows are sorted, the groups are created by looping through the rows. At this point, the GroupByEvaluator is used to determine if rows are to be considered part of the same group.
After that, the GroupByComparer is used to sort the GroupByRows.