Back to Devexpress

How to: Provide Custom Display Text for Data Cells

windowsforms-3077-controls-and-libraries-data-grid-examples-data-presentation-how-to-provide-custom-display-text-for-data-cells.md

latest1.2 KB
Original Source

How to: Provide Custom Display Text for Data Cells

  • Nov 13, 2018

The following example demonstrates how to handle the ColumnView.CustomColumnDisplayText event to display custom display text in data cells. In the example empty strings are displayed within the “Discount” column’s cells if they contain zero values.

The result is shown below:

csharp
using DevExpress.XtraGrid.Views.Base;

private void gridView1_CustomColumnDisplayText(object sender, 
CustomColumnDisplayTextEventArgs e) {
   if(e.Column.FieldName == "Discount")
      if(Convert.ToDecimal(e.Value) == 0) e.DisplayText = "";
}
vb
Imports DevExpress.XtraGrid.Views.Base

Private Sub GridView1_CustomColumnDisplayText(ByVal sender As Object, _
ByVal e As CustomColumnDisplayTextEventArgs) Handles GridView1.CustomColumnDisplayText
   If e.Column.FieldName = "Discount" Then
      If e.Value = 0 Then e.DisplayText = ""
   End If
End Sub