windowsforms-3025-controls-and-libraries-data-grid-examples-painting-how-to-custom-paint-sort-glyphs-within-column-headers.md
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;
};
}
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)
' Handle this event to paint columns headers manually
AddHandler gridView.CustomDrawColumnHeader, Sub(s, e)
If e.Column Is Nothing OrElse e.Column.FieldName <> "Category_Name" Then
Return
End If
' 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.
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