Hi folks
I have a grid and I want to sort the grid by the number of items in groupby row (descending). Any idea how to do that? (I want the row with maximum number of items at top, ...)
UltraGridColumn exposes a SortComparer property, which is of type IComparer. This is a very simple interface with one method, Compare, which enables you to control the way the rows are sorted. I believe the BeforeSortChange event tells you whether the sort was triggered by a group-by column.
The way grouping works is that the grid first sorts the data in the column using the SortComparer (if there is one specified) and then it loop over the sorted rows and groups rows with similar values. So you cannot use the SortComparer property for this because the count will not exist yet when the SortComparer is called.
To sort the GroupByRows, you have to use the GroupByComparer property instead (which also takes an IComparer).
Here is how I did it. Mike, thanks for the pointer ;)
DescendingGroupByRowsSorter
IComparer
IComparer.Compare
(xObj, UltraGridGroupByRow)
(yObj, UltraGridGroupByRow)
' Compare the group rows by the number of items they contain.
y.Rows.Count.CompareTo(x.Rows.Count)
Function
Class
UltraGrid1.InitializeLayout
.UltraGrid1.DisplayLayout.Bands(0).Columns
ugc.GroupByComparer =
Next
Sub
Ok, I've found this
http://help.infragistics.com/Help/NetAdvantage/WinForms/2010.3/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v10.3~Infragistics.Win.UltraWinGrid.UltraGridColumn~GroupByComparer.html
Do I have to do it column by column or is there a global way of doing this?
Hi Mike
Thanks for your answer but can you provide a quick sample?