GridView.CustomDrawColumnHeader Event

Enables you to paint column headers manually.

Namespace: DevExpress.XtraGrid.Views.Grid

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

[DXCategory("CustomDraw")]
public event ColumnHeaderCustomDrawEventHandler CustomDrawColumnHeader
<DXCategory("CustomDraw")>
Public Event CustomDrawColumnHeader As ColumnHeaderCustomDrawEventHandler

Event Data

The CustomDrawColumnHeader event's data class is ColumnHeaderCustomDrawEventArgs. The following properties provide information specific to this event:

Property Description
Appearance Gets the painted element's appearance settings. Inherited from CustomDrawEventArgs.
Bounds Returns a value specifying limits for the drawing area. Inherited from CustomDrawEventArgs.
Cache Provides methods to paint on drawing surfaces in GDI+ and DirectX modes. See DirectX hardware acceleration to learn more. Inherited from CustomDrawEventArgs.
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. Inherited from CustomDrawEventArgs.
Handled Gets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. Inherited from CustomDrawEventArgs.
Info Gets an object providing information necessary to paint a column header.
Painter Gets the painter object that provides the default element painting mechanism. Inherited from CustomDrawObjectEventArgs.

Remarks

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

Do not change cell values, modify the control's layout, or change the control's object model in the events used for custom control painting. Actions that update the layout can cause the control to malfunction.

Examples

This example demonstrates how to fill the "Category_Name" column header with the Coral color.

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) {
    // Handle this event to paint columns headers manually
    gridView.CustomDrawColumnHeader += (s, e) => {
        if (e.Column == null || e.Column.FieldName != "Category_Name")
            return;
        // Fill column headers with the specified colors.
        e.Cache.FillRectangle(Color.Coral, e.Bounds);
        e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
        // Draw the filter and sort buttons.
        foreach (DrawElementInfo info in e.Info.InnerElements) {
            if (!info.Visible) continue;
            ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
        }
        e.Handled = true;
    };
}
See Also