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

Cell Merging

  • 2 minutes to read

The cell merging 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 merging is currently supported only by the Table View in the optimized mode (i.e. the TableView.UseLightweightTemplates property is not set to UseLightweightTemplates.None). To enable the feature, set the view’s TableView.AllowCellMerge property to true. You can disable it for certain columns by setting their ColumnBase.AllowCellMerge property to false. To specify custom cell merge rules, use the TableView.CellMerge event or TableView.CellMergeCommand property.

The cell merging 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 merging 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;
            }
        }
    }
}