Skip to main content
A newer version of this page is available. .
Tab

ASPxGridView.CustomColumnGroup Event

Provides the capability to group data using custom rules.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v19.1.dll

Declaration

public event ASPxGridViewCustomColumnSortEventHandler 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 therefore, no default processing is required. Inherited from GridCustomColumnSortEventArgs.
ListSourceRowIndex1 Gets the index in the data source of the first of the two data items (row, card or record) being compared. Inherited from GridCustomColumnSortEventArgs.
ListSourceRowIndex2 Gets the index in the data source of the second of the two data items (row, card or record) being compared. Inherited from GridCustomColumnSortEventArgs.
Result Gets or sets the result of a custom comparison. Inherited from GridCustomColumnSortEventArgs.
SortOrder Gets the sort order applied to the column (row for ASPxVerticalGrid) being processed. Inherited from GridCustomColumnSortEventArgs.
Value1 Gets the first value being compared. Inherited from GridCustomColumnSortEventArgs.
Value2 Gets the second value being compared. Inherited from GridCustomColumnSortEventArgs.

The event data class exposes the following methods:

Method Description
GetRow1Value(String) Returns the specified column’s value in the first data item (row, card or record) being compared. Inherited from GridCustomColumnSortEventArgs.
GetRow2Value(String) Returns the specified column’s value in the second data item (row, card or record) being compared. Inherited from GridCustomColumnSortEventArgs.

Remarks

Handle the CustomColumnGroup event to implement custom logic for grouping rows. This event is fired when a column’s Settings.SortMode (GridDataColumnSettings.SortMode) property is set to ‘Custom’ and the ASPxGridView’s data is grouped by this column.

Each time the CustomColumnGroup event is fired, two adjacent data rows are compared. If the rows should be combined into the same group, set the GridCustomColumnSortEventArgs.Result parameter to 0. Otherwise, set it to 1 (or -1). The GridCustomColumnSortEventArgs.Handled parameter must be set to true, to indicate that the current comparison was handled, and no default processing is required. If this parameter is left false, the rows will be compared using the default comparison mechanism.

The column by which grouping is applied is identified by the CustomColumnSortEventArgs.Column parameter. The values in the rows that are being compared are specified by the GridCustomColumnSortEventArgs.Value1 and GridCustomColumnSortEventArgs.Value2 parameters.

To replace the default text displayed within group rows, handle the ASPxGridView.CustomGroupDisplayText event.

Note

Since grouping logic is closely coupled with the grid’s sorting logic, and its functionally based on it, it is required to handle both the CustomColumnGroup and ASPxGridView.CustomColumnSort events in a similar manner to correctly implement custom grouping. Otherwise (if only a single CustomColumnGroup event is handled), sorting of the grouped columns might not work correctly in some scenarios.

In addition, handling of the ASPxGridView.CustomGroupDisplayText event might be required to replace the default text displayed within group rows with custom content.

Note

Group modes and custom grouping are not supported in server mode. In this mode, rows are always grouped by values of grouping columns.

Example

This example demonstrates how to implement custom grouping. The data is grouped by the ‘Unit Price’ column, and the column’s rows 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, etc.

The ‘Unit Price’ column’s GridDataColumnSettings.SortMode property is set to ‘Custom’, and the ASPxGridView.CustomColumnGroup and ASPxGridView.CustomColumnSort events are handled identically.

Additionally, the ASPxGridView.CustomGroupDisplayText event is handled to replace the default text displayed within group rows.

The image below shows the result.

CustomColumnGroup

Note

Refer to the How to implement custom grouping logic for ASPxGridView columns online example to review how it works.

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="AccessDataSource1" KeyFieldName="ProductID" 
    OnCustomColumnGroup="ASPxGridView1_CustomColumnGroup" 
    OnCustomColumnSort="ASPxGridView1_CustomColumnSort" 
    OnCustomGroupDisplayText="ASPxGridView1_CustomGroupDisplayText">

    <GroupSummary>
        <dx:ASPxSummaryItem SummaryType="Count" />
    </GroupSummary>

    <Columns>
        <dx:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" 
            VisibleIndex="0">
            <EditFormSettings Visible="False" />
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1">
        </dx:GridViewDataTextColumn>

        <dx:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="2" 
            GroupIndex="0" SortIndex="0" SortOrder="Ascending">
            <PropertiesTextEdit DisplayFormatString="c">
            </PropertiesTextEdit>
            <Settings AllowDragDrop="False" SortMode="Custom" />
        </dx:GridViewDataTextColumn>

        <dx:GridViewDataCheckColumn FieldName="Discontinued" VisibleIndex="3">
        </dx:GridViewDataCheckColumn>
    </Columns>

    <Settings ShowGroupedColumns="True" ShowGroupPanel="True" />
</dx:ASPxGridView>
protected void ASPxGridView1_CustomColumnSort(object sender, DevExpress.Web.ASPxGridView.CustomColumnSortEventArgs e){
    CompareColumnValues(e);
}

protected void ASPxGridView1_CustomColumnGroup(object sender, DevExpress.Web.ASPxGridView.CustomColumnSortEventArgs e){
    CompareColumnValues(e);
}

private void CompareColumnValues(DevExpress.Web.ASPxGridView.CustomColumnSortEventArgs e) {
    if (e.Column.FieldName == "UnitPrice"){
        int res = 0;

        double x = Math.Floor(Convert.ToDouble(e.Value1) / 10);
        double y = Math.Floor(Convert.ToDouble(e.Value2) / 10);
        res = Comparer.Default.Compare(x, y);
        if (res < 0) res = -1;
        else if (res > 0) res = 1;
        if (res == 0 || (x > 9 && y > 9)) res = 0;

        e.Result = res;
        e.Handled = true;
    }
}

protected void ASPxGridView1_CustomGroupDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e){
    if (e.Column.FieldName == "UnitPrice"){
        double d = Math.Floor(Convert.ToDouble(e.Value) / 10);
        string displayText = string.Format("{0:c} - {1:c} ", d * 10, (d + 1) * 10);
        if (d > 9) displayText = string.Format(">= {0:c} ", 100);
        e.DisplayText = displayText;
    }
}
See Also