Skip to content

Handles the CustomColumnDisplayText event to display custom text in grid cells based on a specific condition.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/wpf-grid-display-custom-text-in-cells

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Data Grid – Display Custom Text in Cells Based on a Condition

In this example, the GridControl changes cell display text when a specific condition is met.

If the Discount value is greater than 20, the grid appends (SALE) to the Product Name.

Custom Text in Cells Based on a Condition

Use this technique when you need to:

  • Add labels or status markers to cell values.
  • Update cell text dynamically while the original data remains unchanged.
  • Improve readability and highlight key values.

Implementation Details

The example includes code-behind and MVVM techniques.

Code-Behind

Handle the CustomColumnDisplayText event to replace or extend the text displayed in a cell based on custom conditions.

void grid_CustomColumnDisplayText(object sender, CustomColumnDisplayTextEventArgs e) {
    if (e.Column.FieldName == "ProductName") {
        decimal discount = (decimal)e.GetCellValue("Discount");
        if (discount > 20)
            e.DisplayText += " (SALE)";
    }
}

MVVM

Bind the CustomColumnDisplayTextCommand to a view model command to change the text displayed in a cell based on custom conditions.

public void OnCustomColumnDisplayText(CustomColumnDisplayTextEventArgs e) {
    if (e.Column.FieldName == "ProductName") {
        decimal discount = (decimal)e.GetCellValue("Discount");
        if (discount > 20)
            e.DisplayText += " (SALE)";
    }
}

Files to Review

Code-Behind

MVVM

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Handles the CustomColumnDisplayText event to display custom text in grid cells based on a specific condition.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 8