Skip to main content

How to: Custom Draw Card Fields

The sample code below handles the CardView.CustomDrawCardField event to custom paint fields whose GridColumn.FieldName properties are not set. Such fields are considered header fields, which precede regular data fields.

A header field’s caption is painted centered. The field value is hidden.

CustomDrawCardField

using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Base;

private void cardView1_CustomDrawCardField(object sender, RowCellCustomDrawEventArgs e) {
   if(e.Column.FieldName != "") return;
   e.Cache.FillRectangle(e.Cache.GetSolidBrush(SystemColors.Control), e.Bounds);
   e.Appearance.TextOptions.HAlignment = HorzAlignment.Center;
   e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold);
   e.Appearance.DrawString(e.Cache, e.Column.Caption, e.Bounds);
   e.Handled = true;
}