Back to Devexpress

How to: Custom Draw Card Fields

windowsforms-3033-controls-and-libraries-data-grid-examples-painting-how-to-custom-draw-card-fields.md

latest1.7 KB
Original Source

How to: Custom Draw Card Fields

  • Nov 13, 2018

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.

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

Private Sub CardView1_CustomDrawCardField(ByVal sender As Object, _
ByVal e As RowCellCustomDrawEventArgs) Handles CardView1.CustomDrawCardField
   If Not e.Column.FieldName = "" Then Exit Sub
   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
End Sub