Back to Devexpress

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

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

latest1.7 KB
Original Source

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

  • Nov 13, 2018

The following code shows how to dynamically change the appearance of a card field’s caption in a Layout View via the LayoutView.CustomFieldCaptionStyle event. In the example, the font of a CategoryName field’s caption is changed only in the cards that contain the “Beverages” value in this field.

The result is shown below:

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

private void layoutView1_CustomFieldCaptionStyle(object sender, 
    LayoutViewFieldCaptionStyleEventArgs e) {
    if(e.Column.FieldName != "CategoryName") return;
    LayoutView view = sender as LayoutView;
    bool isBeverage = view.GetRowCellValue(e.RowHandle, e.Column).ToString() == "Beverages";
    if (isBeverage) {
        e.Appearance.FontStyleDelta = FontStyle.Bold;
    }
}
vb
Imports DevExpress.XtraGrid.Views.Layout.Events
Imports DevExpress.XtraGrid.Views.Layout

Private Sub LayoutView1_CustomFieldCaptionStyle(ByVal sender As System.Object, _
ByVal e As LayoutViewFieldCaptionStyleEventArgs) Handles LayoutView1.CustomFieldCaptionStyle
    If e.Column.FieldName <> "CategoryName" Then Return
    Dim view As LayoutView = TryCast(sender, LayoutView)
    Dim isBeverage As Boolean = view.GetRowCellValue(e.RowHandle, e.Column).ToString() = "Beverages"
    If isBeverage Then
        e.Appearance.FontStyleDelta = FontStyle.Bold
    End If
End Sub