GridControl.CustomColumnDisplayTextCommand Property
Gets or sets a command that customizes a data cell‘s display text.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v21.1.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
Property Value
Type | Description |
---|---|
DevExpress.Mvvm.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 both bound and unbound columns. The printed GridControl displays customized text as well.
The DisplayTextArgs.DisplayText property contains a cell’s current display text. To customize the display text, assign a string value to this property.
<dxg:GridControl ItemsSource="{Binding Source}"
CustomColumnDisplayTextCommand="{Binding CustomColumnDisplayTextCommand}">
<dxg:GridControl.View>
<dxg:TableView />
</dxg:GridControl.View>
<dxg:GridColumn FieldName="ProductName" IsSmart="True"/>
<dxg:GridColumn FieldName="Country" IsSmart="True"/>
<dxg:GridColumn FieldName="City" IsSmart="True"/>
<dxg:GridColumn FieldName="Value" IsSmart="True"/>
</dxg:GridControl>
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
public class ViewModel : ViewModelBase {
// ...
[Command]
public void CustomColumnDisplayText(ColumnDisplayTextArgs e) {
if (e.FieldName == "Value")
e.DisplayText = string.Format("{0:n2}", e.Value);
}
}
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 display text, you can instead use techniques described in the following topic: Format Cell Values.
Related GitHub Examples
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.