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.
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.
The example includes code-behind and MVVM techniques.
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)";
}
}
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)";
}
}
- GridControl
- Format Cell Values
- GridControl.CustomColumnDisplayText
- GridControl.CustomColumnDisplayTextCommand
(you will be redirected to DevExpress.com to submit your response)