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 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
- Cell merge is not available in Multiple Row Selection mode.
- If the DataViewBase.NavigationStyle property is set to GridViewNavigationStyle.Row, you cannot merge grid cells.
- The GridControl does not apply Format Conditions for rows and Row Alternation if you set the AllowCellMerge property to
true
. - If the GridControl’s bands contain child bands, the cell merge feature does not work when you export grid data.
Note
Size differences of UI elements affect the cell merge mechanism. If there are render/measure issues with merged cells, set the Use
#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;
}
}
}
}