Back to Devexpress

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

windowsforms-5257-controls-and-libraries-data-grid-examples-painting-how-to-dynamically-customize-the-appearance-of-card-field-values-in-a-layout-view.md

latest1.9 KB
Original Source

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

  • Nov 13, 2018

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:

csharp
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;
}
vb
Imports DevExpress.XtraGrid.Views.Layout.Events
Imports DevExpress.XtraGrid.Views.Layout

Private Sub LayoutView1_CustomFieldValueStyle(ByVal sender As System.Object, _
ByVal e As LayoutViewFieldValueStyleEventArgs) Handles LayoutView1.CustomFieldValueStyle
   If e.Column.FieldName <> "Description" AndAlso e.Column.FieldName <> "CategoryName" Then Return
   Dim view As LayoutView = TryCast(sender, LayoutView)
   Dim isBeverage As Boolean = view.GetRowCellValue(e.RowHandle, "CategoryName").ToString() = 
      "Beverages"
   If isBeverage Then
       e.Appearance.ForeColor = Color.Red
   End If
End Sub