下列代码展示了如何通过 LayoutView.CustomFieldCaptionStyle 事件,在布局视图中动态改变卡片字段标题的外观。 在本示例中,只在 CategoryName 字段包含“Beverages”取值的卡片中,才改变此字段的标题的字体。

结果显示如下:

C#CopyCode image复制代码
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.Font = new Font(e.Appearance.Font, FontStyle.Bold);
    }
}
Visual BasicCopyCode image复制代码
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.Font = New Font(e.Appearance.Font, FontStyle.Bold)
    End If
End Sub