Skip to main content

Cell Merge

  • 2 minutes to read

The cell merge feature allows your applications to deliver data clarity and avoid duplication by merging neighboring data cells across different rows whenever they display matching values.

cell merging

Cell merge is currently supported only by the Table View in the optimized mode (the TableView.UseLightweightTemplates property is not set to None). To enable the feature, set the view’s TableView.AllowCellMerge property to true. To disable it for certain columns, set their ColumnBase.AllowCellMerge property to false. To specify custom cell merge rules, use the TableView.CellMerge event or TableView.CellMergeCommand property.

The cell merge feature doesn’t prevent you from editing individual cells and supports major data shaping operations including sorting, grouping, and master-detail.

Limitations

Note

Size differences of UI elements affect the cell merge mechanism. If there are render/measure issues with merged cells, set the UseLayoutRounding property to true at the window level.

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;
            }
        }
    }
}