Skip to main content

TableView.CellMerge Event

Allows you to specify custom cell merge rules.

Namespace: DevExpress.Xpf.Grid

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

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public event CellMergeEventHandler CellMerge

Event Data

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

Property Description
CellValue1 Gets the value of the first cell processed by the TableView.CellMerge event handler.
CellValue2 Gets the value of the second cell processed by the TableView.CellMerge event handler.
Column Gets the column that contains the cells processed by the TableView.CellMerge event handler.
Handled Gets or sets whether a cell merge operation is handled and no default processing is required.
Merge Gets or sets whether the cells processed by the TableView.CellMerge event handler will be merged.
RowHandle1 Gets the row handle of the first row processed by the TableView.CellMerge event handler.
RowHandle2 Gets the row handle of the second row processed by the TableView.CellMerge event handler.

Remarks

Set the TableView.AllowCellMerge property to true to merge adjacent cells in each column if they have matching values.

The CellMerge event allows you to control how the GridControl merges cells. For example, you can merge adjacent cells with different values based on custom logic.

If you want to maintain a clean MVVM pattern and specify custom merge rules in a View Model, create a command and bind it to the CellMergeCommand property.

Example

The code sample below merges cells in the Order Date column if they have the same month and year:

DevExpress WPF | Grid Control - Custom Cell Merge Rules

<dxg:GridControl ItemsSource="{Binding Orders}">
    <dxg:GridColumn FieldName="OrderDate" AllowCellMerge="True">
        <dxg:GridColumn.EditSettings>
            <dxe:DateEditSettings DisplayFormat="MMMM yyyy"/>
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>
    <!-- ... -->
    <dxg:GridControl.View>
        <dxg:TableView x:Name="view" 
                       CellMerge="view_CellMerge">
    </dxg:TableView>
    </dxg:GridControl.View>
</dxg:GridControl>
void view_CellMerge(object sender, DevExpress.Xpf.Grid.CellMergeEventArgs e) {
    if (e.Column.FieldName == nameof(Order.OrderDate)) {
        if (((DateTime)e.CellValue1).Month == ((DateTime)e.CellValue2).Month 
        && ((DateTime)e.CellValue1).Year == ((DateTime)e.CellValue2).Year) {
            e.Merge = true;
            e.Handled = true;
        }
    }
}
See Also