Skip to main content
All docs
V25.1
  • GridControl.CustomColumnDisplayTextCommand Property

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

    Namespace: DevExpress.Xpf.Grid

    Assembly: DevExpress.Xpf.Grid.v25.1.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)";
            }
        }
    }
    
    See Also