How to: Custom Paint Sort Glyphs Within Column Headers
- 2 minutes to read
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;
};
}