wpf-devexpress-dot-xpf-dot-grid-dot-tableview-8e838425.md
Gets or sets a command that allows you to specify custom cell merge rules.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public ICommand<CellMergeArgs> CellMergeCommand { get; set; }
Public Property CellMergeCommand As ICommand(Of CellMergeArgs)
| Type | Description |
|---|---|
| ICommand<CellMergeArgs> |
A command that allows you to specify custom cell merge rules.
|
Bind a command to the CellMergeCommand property to maintain a clean MVVM pattern. The command works like a CellMerge event handler and allows you to specify custom merge rules in a View Model.
Set the TableView.AllowCellMerge property to true to merge adjacent cells in each column if they have matching values.
The CellMergeCommand property allows you to control how the GridControl merges cells. For example, you can merge adjacent cells with different values based on custom logic.
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;
}
}
}
}
Public Class ViewModel
Inherits ViewModelBase
' ...
<Command>
Public Sub CellMerge(ByVal args As CellMergeArgs)
If args.FieldName = NameOf(Order.OrderDate) Then
If (CType(args.FirstCellValue, DateTime)).Month = (CType(args.SecondCellValue, DateTime)).Month AndAlso (CType(args.FirstCellValue, DateTime)).Year = (CType(args.SecondCellValue, DateTime)).Year Then
args.Merge = True
End If
End If
End Sub
End Class
See Also