Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
336
Custom grouping using IGroupByEvaluatorEx and special sort logic
posted

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