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 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
- Cell merging is not available in Multiple Row Selection and Multiple Cell Selection modes.
- If the DataViewBase.NavigationStyle property is set to GridViewNavigationStyle.Row, you cannot merge grid cells.
- If the GridControl’s bands contain child bands, the cell merging does not work when you export grid data.
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:
<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;
}
}
}
}