Skip to main content
All docs
V24.2

GridControl.CustomColumnDisplayTextCommand Property

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

Namespace: DevExpress.Xpf.Grid

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

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public ICommand<ColumnDisplayTextArgs> CustomColumnDisplayTextCommand { get; set; }

Property Value

Type Description
ICommand<ColumnDisplayTextArgs>

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.

If column data is sorted or grouped, the SourceIndex property returns an invalid value. As a result, you cannot determine the processed row and obtain other cell values. To customize the display text, use techniques described in the following topic instead: Format Cell Values.

Example

The following example shows how to display custom text in data cells. In this example, the GridControl adds the (SALE) string to the Product Name if a value in the Discount column is greater than 20:

DevExpress WPF | Grid Control - Custom Display Text

View Example: How to display custom text within data cells

<dxg:GridControl ItemsSource="{Binding InvoiceList}" 
                 AutoGenerateColumns="AddNew" 
                 CustomColumnDisplayTextCommand="{Binding CustomColumnDisplayTextCommand}"/>
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
// ...
public class MainViewModel : ViewModelBase {
// ...
    [Command]
    public void CustomColumnDisplayText(ColumnDisplayTextArgs args) {
        if(args.FieldName != nameof(Invoice.ProductName) || args.SourceIndex < 0) {
            return;
        }
        if(InvoiceList[args.SourceIndex].Discount > 20) {
            args.DisplayText += " (SALE)";
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomColumnDisplayTextCommand property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also