UltraWebGrid in OutlookGroupBy Mode: How to count total number of rows in subgroups

Infragistics UltraWebGrid has a nice feature – OutlookGroupBy mode – which allows to group rows by common field either by dragging them into a GroupBy Box or programmatically.

The only drawback – when you have several levels of groupings (group within a group) – the outer group shows count of inner groups, not total number of individual rows within a group.

before

When I contacted Infragistics tech support asking how to show total count of rows within a group they told me it was impossible. Well, turned out it wasn’t entirely true.

First thing you have to do is remove automatic counting from grid’s GroupByRowDescriptionMaskDefault property – just leave column caption and field value:

GridProperty

Next, create a function which returns total row count of a GroupBy row:

Function GroupRowCount(ByVal i_oRow As UltraGridRow) As Integer
Dim iRowCount As Integer = 0

     If i_oRow.Rows(0).HasChildRows Then
         
For Each oRow As UltraGridRow In i_oRow.Rows
               iRowCount += GroupRowCount(oRow)
         
Next
     Else
         
iRowCount = i_oRow.Rows.Count
     End If

     Return iRowCount

End Function

What it does – takes a GroupBy row as an input parameter. If it’s first child row has children of its own – that means it’s a GroupBy row as well, so function calls itself recursively on each of those rows, otherwise function simple returns count of rows.

And the last step – capture grid’s InitializeGroupByRow event and insert this code to call the function:


Dim grRow As GroupByRow = e.Row

grRow.Text &= ” (“ & GroupRowCount(grRow) & “)”

Event handlers takes Row property from event arguments, casts it as GroupByRow and calls the count function. The result:

after

3 replies on “UltraWebGrid in OutlookGroupBy Mode: How to count total number of rows in subgroups”

  1. @stanko
    Glad the information was useful. There is also a way to display not only Count, but other aggregates (Sum, Avg, Min, Max) described here. This also includes a slightly corrected version of row count described above, since it can sometimes produce double caption in Group Row header

Leave a Reply

Your email address will not be published. Required fields are marked *