Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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;
    };
}