TableView.CellMerge Event
Allows you to specify custom cell merge rules.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v24.2.dll
NuGet Package: DevExpress.Wpf.Grid.Core
#Declaration
#Event Data
The CellMerge event's data class is CellMergeEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Cell |
Gets the value of the first cell processed by the Table |
Cell |
Gets the value of the second cell processed by the Table |
Column |
Gets the column that contains the cells processed by the Table |
Handled | Gets or sets whether a cell merge operation is handled and no default processing is required. |
Merge |
Gets or sets whether the cells processed by the Table |
Row |
Gets the row handle of the first row processed by the Table |
Row |
Gets the row handle of the second row processed by the Table |
#Remarks
Set the TableView.AllowCellMerge property to true to merge adjacent cells in each column if they have matching values.
The CellMerge event allows you to control how the GridControl merges cells. For example, you can merge adjacent cells with different values based on custom logic.
If you want to maintain a clean MVVM pattern and specify custom merge rules in a View Model, create a command and bind it to the CellMergeCommand property.
#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 x:Name="view"
CellMerge="view_CellMerge">
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
void view_CellMerge(object sender, DevExpress.Xpf.Grid.CellMergeEventArgs e) {
if (e.Column.FieldName == nameof(Order.OrderDate)) {
if (((DateTime)e.CellValue1).Month == ((DateTime)e.CellValue2).Month
&& ((DateTime)e.CellValue1).Year == ((DateTime)e.CellValue2).Year) {
e.Merge = true;
e.Handled = true;
}
}
}