Back to Devexpress

Process Group Rows

wpf-6140-controls-and-libraries-data-grid-grouping-processing-group-rows.md

latest5.1 KB
Original Source

Process Group Rows

  • Aug 25, 2023
  • 3 minutes to read

Group Rows and Group Levels

When grouping is applied, group rows organize data into a tree. Group rows are virtual objects. They do not exist in the grid’s data source. Group rows are automatically created when data grouping is applied to combine records with identical values within grouping columns. Ungrouping data automatically removes group rows. Data rows are displayed at the bottommost hierarchy level, and can be accessed by expanding group rows.

Group rows are uniquely identified by their handles. Group row handles are negative (starting from -1 ), determining the order in which group rows appear within a View according to the sort and filter settings. Refer to the Identifying Rows and Cards topic for more information.

MethodDescription
GridControl.IsGroupRowHandleGets whether a row handle corresponds to a group row.
GridControl.GetRowLevelByRowHandle, GridControl.GetRowLevelByVisibleIndexObtains the grouping level at which a row (group or data row) resides.

Obtain the Number of Group Rows

The total number of visible rows is returned by the DataControlBase.VisibleRowCount property. The GridControl.GetRowHandleByVisibleIndex method is used to obtain the processed row’s handle by its position within the view. The GridControl.IsGroupRowHandle method is used to identify whether the processed row is the group row.

csharp
using DevExpress.Xpf.Grid;

// ...
int GetVisibleGroupRowCount(GridControl grid) {
    int count = 0;
    for (int i = 0; i < grid.VisibleRowCount; i++) {
        int rowHandle = grid.GetRowHandleByVisibleIndex(i);
        if(grid.IsGroupRowHandle(rowHandle))
            count++;
    }
    return count;
}
vb
Imports DevExpress.Xpf.Grid

' ...
Private Function GetVisibleGroupRowCount(ByVal grid As GridControl) As Integer
    Dim count As Integer = 0

    For i As Integer = 0 To grid.VisibleRowCount - 1
        Dim rowHandle As Integer = grid.GetRowHandleByVisibleIndex(i)
        If grid.IsGroupRowHandle(rowHandle) Then count += 1
    Next

    Return count
End Function

The following code sample gets the total number of existing group rows:

csharp
using DevExpress.Xpf.Grid;

// ...
int GetTotalGroupRowCount(GridControl grid) {
    int groupRowCount = 0;
    for (int i = -1; grid.GetGroupRowValue(i) != null; i--)
        groupRowCount++;
    return groupRowCount;
}
vb
Imports DevExpress.Xpf.Grid

' ...
Private Function GetTotalGroupRowCount(ByVal grid As GridControl) As Integer
    Dim groupRowCount As Integer = 0
    Dim i As Integer = -1

    While grid.GetGroupRowValue(i) IsNot Nothing
        groupRowCount += 1
        i -= 1
    End While

    Return groupRowCount
End Function

Get Group Row Info

MethodDescription
GridControl.GetGroupRowValueReturns a value of the specified group row.
GridControl.GetGroupSummaryValueReturns the specified group summary value displayed within the specified group row.

Iterate Through Child Rows

To iterate through the child rows belonging to a group row, use the following methods:

MethodDescription
GridControl.GetChildRowCountReturns the number of child rows (group or data) contained within the specified group row.
GridControl.GetChildRowHandleReturns the handle of the row contained within the specified group row, at the specified position.
GridControl.GetParentRowHandleReturns the handle of the group row that owns the specified group or data row.

Custom Group Display Text

MemberDescription
GridControl.CustomGroupDisplayTextAllows you to replace the default text within group rows.
GridControl.CustomGroupDisplayTextCommandGets or sets a command that displays custom text in group rows.