Back to Devexpress

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

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

latest1.8 KB
Original Source

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

  • Nov 13, 2018

The following example shows how to handle the LayoutView.CustomCardStyle event to change the border color for cards that contain “London” in the City field. The event handler provides different border colors for the focused and non-focused card states.

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

private void layoutView1_CustomCardStyle(object sender, DevExpress.XtraGrid.Views.Layout.Events.LayoutViewCardStyleEventArgs e) {
    LayoutView view = sender as LayoutView; 
    string city = view.GetRowCellDisplayText(e.RowHandle, colCity);
    if (city != "London") return;
    if ((e.State & GridRowCellState.Focused) != 0)
        e.Appearance.BorderColor = Color.FromArgb(192, 192, 255);
    else
        e.Appearance.BorderColor = Color.MediumOrchid;
}
vb
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.Layout

Private Sub LayoutView1_CustomCardStyle(sender As Object, e As DevExpress.XtraGrid.Views.Layout.Events.LayoutViewCardStyleEventArgs) Handles LayoutView1.CustomCardStyle
    Dim view As LayoutView = CType(sender, LayoutView)
    Dim city As String = view.GetRowCellDisplayText(e.RowHandle, colCity)
    If city <> "London" Then Return
    If (e.State And GridRowCellState.Focused) <> 0 Then
        e.Appearance.BorderColor = Color.FromArgb(192, 192, 255)
    Else
        e.Appearance.BorderColor = Color.MediumOrchid
    End If
End Sub