Back to Devexpress

TreeListView.CustomColumnDisplayTextCommand Property

wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-a2715068.md

latest3.3 KB
Original Source

TreeListView.CustomColumnDisplayTextCommand Property

Gets or sets a command that customizes a data cell‘s display text.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

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

Property Value

TypeDescription
ICommand<NodeDisplayTextArgs>

Contains properties that identify the processed cell.

|

Remarks

Bind a command to the CustomColumnDisplayTextCommand property to maintain a clean MVVM pattern. The command works like a CustomColumnDisplayText event handler and allows you to customize a data cell’s display text in a View Model.

The command is called for bound and unbound columns. The printed GridControl also displays customized text.

The DisplayTextArgs.DisplayText property contains a cell’s display text. To customize the display text, assign a string value to this property.

xaml
<dxg:GridControl ItemsSource="{Binding Source}">
    <dxg:GridControl.View>
        <dxg:TreeListView CustomColumnDisplayTextCommand="{Binding CustomColumnDisplayTextCommand}"/>
    </dxg:GridControl.View>
    <dxg:TreeListColumn FieldName="ProductName" IsSmart="True"/>
    <dxg:TreeListColumn FieldName="Country" IsSmart="True"/>
    <dxg:TreeListColumn FieldName="City" IsSmart="True"/>
    <dxg:TreeListColumn FieldName="Value" IsSmart="True"/>
</dxg:GridControl>
csharp
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;

public class ViewModel : ViewModelBase {
    // ...

    [Command]
    public void CustomColumnDisplayText(NodeDisplayTextArgs e) {
        if (e.FieldName == "Value")
            e.DisplayText = string.Format("{0:n2}", e.Value);
    }
}
vb
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf

Public Class ViewModel
    Inherits ViewModelBase

    <Command>
    Public Sub CustomColumnDisplayText(ByVal e As NodeDisplayTextArgs)
        If e.FieldName = "Value" 
        Then e.DisplayText = String.Format("{0:n2}", e.Value)
    End Sub
End Class

See Also

Format Cell Values

TreeListView Class

TreeListView Members

DevExpress.Xpf.Grid Namespace