Skip to main content
All docs
V23.2

TableView.CellMergeCommand Property

Gets or sets a command that 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 ICommand<CellMergeArgs> CellMergeCommand { get; set; }

Property Value

Type Description
ICommand<CellMergeArgs>

A command that allows you to specify custom cell merge rules.

Remarks

Bind a command to the CellMergeCommand property to maintain a clean MVVM pattern. The command works like a CellMerge event handler and allows you to specify custom merge rules in a View Model.

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

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

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 CellMergeCommand="{Binding CellMergeCommand}">
    </dxg:TableView>
    </dxg:GridControl.View>
</dxg:GridControl>
public class ViewModel : ViewModelBase {
    // ...
    [Command]
    public void CellMerge(CellMergeArgs args) {
        if(args.FieldName == nameof(Order.OrderDate)) {
            if(((DateTime)args.FirstCellValue).Month == ((DateTime)args.SecondCellValue).Month 
            && ((DateTime)args.FirstCellValue).Year == ((DateTime)args.SecondCellValue).Year) {
                args.Merge = true;
            }
        }
    }
}
See Also