Skip to main content

GridControl.CustomGroupDisplayText Event

Allows you to display custom text in group rows.

Namespace: DevExpress.WinUI.Grid

Assembly: DevExpress.WinUI.Grid.v23.2.dll

NuGet Package: DevExpress.WinUI

Declaration

public event CustomGroupDisplayTextEventHandler CustomGroupDisplayText

Event Data

The CustomGroupDisplayText event's data class is CustomGroupDisplayTextEventArgs. The following properties provide information specific to this event:

Property Description
DisplayText Gets or sets text displayed in the group row.
Row Gets the processed row. Inherited from RowEventArgs.
RowHandle Gets the processed row’s handle. Inherited from RowEventArgs.
Source Gets the GridControl that raised this event. Inherited from RowEventArgs.

Remarks

If the built-in grouping modes do not meet your requirements, you can implement custom logic. To do this, set the ColumnBase.SortMode property to Custom, and handle the GridControl.CustomColumnGroup event. To change text displayed within group rows, handle the CustomGroupDisplayText event.

Refer to the following help topic for more information: Group Data.

Example

The following code sample shows how to apply custom rules to group rows. When you group data by the Unit Price column, rows in this column that have values between 0 and 10 are combined into a single group. Rows whose values fall between 10 and 20 are combined into another group, and so forth.

DevExpress WinUI | Grid Control - CustomColumnGroup

<Window ...
    xmlns:dxg="using:DevExpress.WinUI.Grid">
    <dxg:GridControl ItemsSource="{x:Bind ViewModel.Source}" 
                     AutoGenerateColumns="False" 
                     CustomColumnGroup="GridControl_CustomColumnGroup" 
                     CustomGroupDisplayText="GridControl_CustomGroupDisplayText" 
                     ShowGroupedColumns="True">
        <dxg:GridControl.Columns>
            <dxg:GridTextColumn FieldName="ProductName"/>
            <dxg:GridTextColumn FieldName="Country"/>
            <dxg:GridTextColumn FieldName="City"/>
            <dxg:GridSpinEditColumn FieldName="UnitPrice" SortMode="Custom" GroupIndex="0"/>
            <dxg:GridTextColumn FieldName="Quantity"/>
        </dxg:GridControl.Columns>
    </dxg:GridControl>
</Window>
void GridControl_CustomColumnGroup(object sender, DevExpress.WinUI.Grid.CustomColumnSortEventArgs e) {
    if(e.Column.FieldName != "UnitPrice")
        return;
    double x = Math.Floor(Convert.ToDouble(e.Value1) / 10);
    double y = Math.Floor(Convert.ToDouble(e.Value2) / 10);
    e.Result = x > 9 && y > 9 ? 0 : x.CompareTo(y);
    e.Handled = true;
}

void GridControl_CustomGroupDisplayText(object sender, DevExpress.WinUI.Grid.CustomGroupDisplayTextEventArgs e) {
    if(e.Column.FieldName != "UnitPrice")
        return;
    string interval = IntervalByValue(e.Value);
    e.DisplayText = interval;
}
// Gets the interval which contains the specified value.
string IntervalByValue(object val) {
    double d = Math.Floor(Convert.ToDouble(val) / 10);
    string ret = string.Format("{0:c} - {1:c} ", d * 10, (d + 1) * 10);
    if(d > 9)
        ret = string.Format(">= {0:c} ", 100);
    return ret;
}
See Also