Back to Devexpress

TableView.CellMergeCommand Property

wpf-devexpress-dot-xpf-dot-grid-dot-tableview-8e838425.md

latest3.8 KB
Original Source

TableView.CellMergeCommand Property

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

Declaration

csharp
public ICommand<CellMergeArgs> CellMergeCommand { get; set; }
vb
Public Property CellMergeCommand As ICommand(Of CellMergeArgs)

Property Value

TypeDescription
ICommand<CellMergeArgs>

A command that allows you to specify custom cell merge rules.

|

Remarks

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.

Example

The code sample below merges cells in the Order Date column if they have the same month and year:

xaml
<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>
csharp
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;
            }
        }
    }
}
vb
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

TableView.AllowCellMerge

ColumnBase.AllowCellMerge

TableView Class

TableView Members

DevExpress.Xpf.Grid Namespace