Skip to main content

How to: Dynamically Customize the Appearance of Card Field Values in a Layout View

The following code shows how to dynamically customize the appearance of field values in a Layout View dependant on specific conditions.

In the example the LayoutView.CustomFieldValueStyle event is handled to customize the appearance of Description and CategoryName field values. Values of these fields are only painted in red in the cards that have the CategoryName field set to “Beverages”.

The result is shown below:

LayoutView_CustomFieldValueStyle_ex

using DevExpress.XtraGrid.Views.Layout.Events;
using DevExpress.XtraGrid.Views.Layout;

private void layoutView1_CustomFieldValueStyle(object sender, 
LayoutViewFieldValueStyleEventArgs e) {
    if (e.Column.FieldName != "Description" && e.Column.FieldName != "CategoryName") return;
    LayoutView view = sender as LayoutView;
    bool isBeverage = view.GetRowCellValue(e.RowHandle, "CategoryName").ToString() == 
        "Beverages";
    if (isBeverage)
        e.Appearance.ForeColor = Color.Red;
}