Back to Devexpress

GridControl.CustomColumnDisplayText Event

wpf-devexpress-dot-xpf-dot-grid-dot-gridcontrol-c5bdf92f.md

latest7.2 KB
Original Source

GridControl.CustomColumnDisplayText Event

Allows you to customize 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 event CustomColumnDisplayTextEventHandler CustomColumnDisplayText
vb
Public Event CustomColumnDisplayText As CustomColumnDisplayTextEventHandler

Event Data

The CustomColumnDisplayText event's data class is CustomColumnDisplayTextEventArgs. The following properties provide information specific to this event:

PropertyDescription
ColumnGets the column which owns the processed cell.
DisplayTextGets or sets the display text for the cell currently being processed.
ListSourceIndexGets the index of a record in a data source that corresponds to the processed data row.
RowGets the row which owns the processed cell.
RowHandleGets the processed row’s handle.
ShowAsNullTextSpecifies whether text corresponding to a null value appears faded.
SourceGets the grid control that raised the event.
ValueGets the processed cell’s value.

Remarks

The CustomColumnDisplayText event occurs for bound and unbound columns. The printed GridControl also displays customized text.

The CustomColumnDisplayTextEventArgs.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 event’s RowHandle and ListSourceRowIndex properties return invalid values. 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.

If you want to maintain a clean MVVM pattern and customize a data cell’s display text in a View Model, create a command and bind it to the CustomColumnDisplayTextCommand property.

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:

View Example: How to display custom text within data cells

xaml
<dxg:GridControl CustomColumnDisplayText="gridControl1_CustomColumnDisplayText" Name="gridControl1">
    <dxg:GridControl.Columns>
        <dxg:GridColumn x:Name="columnProductName" FieldName="ProductName" />
        <dxg:GridColumn FieldName="Price" />
        <dxg:GridColumn FieldName="Discount" />
    </dxg:GridControl.Columns>
</dxg:GridControl>
cs
void gridControl1_CustomColumnDisplayText(object sender, CustomColumnDisplayTextEventArgs e) {
    if(!e.Column.Equals(columnProductName) || e.ListSourceIndex < 0)
        return;
    if((double)gridControl1.GetCellValue(e.RowHandle, "Discount") > 20)
        e.DisplayText = ((string)e.Value) + " (SALE)";
}
vb
Private Sub gridControl1_CustomColumnDisplayText(ByVal sender As Object, ByVal e As CustomColumnDisplayTextEventArgs)
    If Not e.Column.Equals(Me.columnProductName) OrElse e.ListSourceIndex < 0 Then Return
    If CDbl(Me.gridControl1.GetCellValue(e.RowHandle, "Discount")) > 20 Then e.DisplayText =(CStr(e.Value)) & " (SALE)"
End Sub

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

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.

wpf-grid-display-custom-text-in-cells/CS/DisplayCustomText_CodeBehind/MainWindow.xaml#L11

xml
<Grid>
    <dxg:GridControl CustomColumnDisplayText="gridControl1_CustomColumnDisplayText" Name="gridControl1">
        <dxg:GridControl.Columns>

wpf-grid-display-custom-text-in-cells/CS/DisplayCustomText_CodeBehind/obj/Debug/net8.0-windows/MainWindow.g.cs#L99

csharp
#line 11 "..\..\..\MainWindow.xaml"
this.gridControl1.CustomColumnDisplayText += new DevExpress.Xpf.Grid.CustomColumnDisplayTextEventHandler(this.gridControl1_CustomColumnDisplayText);

wpf-grid-display-custom-text-in-cells/VB/DisplayCustomText_CodeBehind/obj.NetFX/Debug/MainWindow.g.vb#L97

vb
#ExternalSource("..\..\MainWindow.xaml",11)
AddHandler Me.gridControl1.CustomColumnDisplayText, New DevExpress.Xpf.Grid.CustomColumnDisplayTextEventHandler(AddressOf Me.gridControl1_CustomColumnDisplayText)

See Also

Format Cell Values

GridControl Class

GridControl Members

DevExpress.Xpf.Grid Namespace