SpreadsheetControl.CustomDrawColumnHeader Event

Enables the column header to be painted manually.

Namespace: DevExpress.XtraSpreadsheet

Assembly: DevExpress.XtraSpreadsheet.v20.1.dll


public event CustomDrawColumnHeaderEventHandler CustomDrawColumnHeader
Public Event CustomDrawColumnHeader As CustomDrawColumnHeaderEventHandler

Event Data

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

Property Description
Appearance Provides access to the properties that control the appearance of a worksheet header. Inherited from CustomDrawHeaderEventArgsBase.
BackColor Gets the background color of the header. Inherited from CustomDrawHeaderEventArgsBase.
Bounds Gets the header's bound rectangle. Inherited from CustomDrawHeaderEventArgsBase.
Cache Gets an object that serves as the storage for pens, fonts and brushes. Inherited from CustomDrawObjectEventsArgs.
ColumnIndex Returns the column index of the column header being painted.
Control Provides access to the SpreadsheetControl that raised the event. Inherited from CustomDrawHeaderEventArgsBase.
Font Gets the font used to paint the header caption. Inherited from CustomDrawHeaderEventArgsBase.
ForeColor Gets the color used to paint the header caption text. Inherited from CustomDrawHeaderEventArgsBase.
Graphics Gets an object used for painting. Inherited from CustomDrawObjectEventsArgs.
Handled Gets or sets whether an event is handled. If true, the default actions are not required. Inherited from CustomDrawObjectEventsArgs.
IsHovered Gets whether a mouse is currently over the worksheet header. Inherited from CustomDrawHeaderEventArgsBase.
IsSelected Gets whether the current column contains selected cell(s). Inherited from CustomDrawHeaderEventArgsBase.
Text Gets the text of the header caption. Inherited from CustomDrawHeaderEventArgsBase.


The CustomDrawColumnHeader event is raised before a column header is painted. Event arguments properties provide the objects and information required to paint the column header.

Set the CustomDrawObjectEventsArgs.Handled property to true to cancel default painting. Use the CustomDrawObjectEventsArgs.DrawDefault method to perform default painting within the event handler.

The following code obtains the column names located in the hidden worksheet and displays them instead of the default column headings. A worksheet appears as shown in the image below.


using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Spreadsheet;
using DevExpress.XtraSpreadsheet;
        void spreadsheetControl1_CustomDrawColumnHeader(object sender, CustomDrawColumnHeaderEventArgs e)
            e.Handled = true;
            Color foreColor = Color.Blue;
            Rectangle textBounds = e.Bounds;
            Font headingFont = new Font(e.Font, FontStyle.Italic);
            Worksheet settingsSheet = spreadsheetControl1.Document.Worksheets["SheetSettings"];
            string text = settingsSheet.Cells[0, e.ColumnIndex].DisplayText;
            if (text != String.Empty)
                StringFormat formatHeaderText = new StringFormat();
                formatHeaderText.LineAlignment = StringAlignment.Center;
                formatHeaderText.Alignment = StringAlignment.Center;
                formatHeaderText.Trimming = StringTrimming.EllipsisCharacter;
                e.Graphics.DrawString(text, headingFont, e.Cache.GetSolidBrush(foreColor), textBounds, formatHeaderText);
See Also