GridControl.CustomColumnGroup Event
Provides the capability to group data using custom rules.
Namespace: DevExpress.WinUI.Grid
Assembly: DevExpress.WinUI.Grid.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
public event CustomColumnSortEventHandler CustomColumnGroup
#Event Data
The CustomColumnGroup event's data class is CustomColumnSortEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Column | Gets the column whose values are being compared. |
Handled | Gets or sets whether a comparison operation is handled and no default processing is required. |
List |
Gets the index of the first of the two rows being compared in the data source. |
List |
Gets the index of the second of the two rows being compared in the data source. |
Result | Gets or sets the result of a custom comparison. |
Sort |
Gets the sort order applied to the column. |
Source | Gets the grid control that raised the event. |
Value1 | Gets the first value being compared. |
Value2 | Gets the second value being compared. |
#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 CustomColumnGroup event. To change the text displayed within group rows, handle the GridControl.CustomGroupDisplayText event.
For more information, refer to the following help topic: 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.
<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;
}