The event handler receives an argument of type ColumnHeaderCustomDrawEventArgs containing data related to this event.
The following
ColumnHeaderCustomDrawEventArgs properties provide information specific to this event.
Property |
Description |
Appearance |
Gets the painted element's appearance settings. |
Bounds |
Returns a value specifying limits for the drawing area. |
Cache |
Provides methods to paint on drawing surfaces in GDI+ and DirectX modes. See DirectX Hardware Acceleration to learn more. |
Column |
Gets the GridColumn whose header is to be drawn. Returns null if an "empty column header" is currently being painted. |
Graphics |
A GDI+ drawing surface. Use the CustomDrawEventArgs.Cache property instead if you enable the DirectX Hardware Acceleration. |
Handled |
Gets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. |
Info |
Gets an object providing information necessary to paint a Column Header. |
Painter |
Gets the painter object that provides the default element painting mechanism. |
The CustomDrawColumnHeader event is raised each time a column header is about to be painted. The column is identified by the ColumnHeaderCustomDrawEventArgs.Column parameter. See the Custom Painting Basics and Custom Painting Scenarios topics for information on using custom draw events.
Important
Never change cell values or modify the control's layout on this event, or any other event designed to tune the control's appearance. Any action that causes a layout update can cause the control to malfunction.

Example
This example demonstrates how to fill the "Category_Name" column header with the Coral color.
C# |
using DevExpress.Utils;
using DevExpress.Utils.Drawing;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
private void Form3_Load1(object sender, EventArgs e) {
CustomDrawColumnHeader(gridControl1, gridView1);
}
public static void CustomDrawColumnHeader(GridControl gridControl, GridView gridView) {
gridView.CustomDrawColumnHeader += (s, e) => {
if (e.Column == null || e.Column.FieldName != "Category_Name")
return;
e.Cache.FillRectangle(Color.Coral, e.Bounds);
e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
foreach (DrawElementInfo info in e.Info.InnerElements) {
if (!info.Visible) continue;
ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
}
e.Handled = true;
};
}
|
VB |
Imports DevExpress.Utils
Imports DevExpress.Utils.Drawing
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Private Sub Form3_Load1(ByVal sender As Object, ByVal e As EventArgs)
CustomDrawColumnHeader(gridControl1, gridView1)
End Sub
Public Shared Sub CustomDrawColumnHeader(ByVal gridControl As GridControl, ByVal gridView As GridView)
AddHandler gridView.CustomDrawColumnHeader, Sub(s, e)
If e.Column Is Nothing OrElse e.Column.FieldName <> "Category_Name" Then
Return
End If
e.Cache.FillRectangle(Color.Coral, e.Bounds)
e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect)
For Each info As DrawElementInfo In e.Info.InnerElements
If Not info.Visible Then
Continue For
End If
ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo)
Next info
e.Handled = True
End Sub
End Sub
|