Skip to main content
A newer version of this page is available. .

SpreadsheetControl.CustomDrawRowHeader Event

Enables the row header to be painted manually.

Namespace: DevExpress.XtraSpreadsheet

Assembly: DevExpress.XtraSpreadsheet.v19.1.dll

Declaration

public event CustomDrawRowHeaderEventHandler CustomDrawRowHeader

Event Data

The CustomDrawRowHeader event's data class is CustomDrawRowHeaderEventArgs. 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.
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.
RowIndex Returns the column index of the row header being painted.
Text Gets the text of the header caption. Inherited from CustomDrawHeaderEventArgsBase.

The event data class exposes the following methods:

Method Description
DrawDefault() Renders the element using the default drawing mechanism. Inherited from CustomDrawObjectEventsArgs.

Remarks

The CustomDrawRowHeader event is raised before a row header is painted. Event arguments properties provide the objects and information required to paint the row 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 displays a row number every five rows. The worksheet appears as shown in the image below.

CustomDrawColumnHeader

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Spreadsheet;
using DevExpress.XtraSpreadsheet;
        void spreadsheetControl1_CustomDrawRowHeader(object sender, CustomDrawRowHeaderEventArgs e)
        {
            e.Handled = true;

            if ((e.RowIndex + 1) % 5 == 0)
            {
                System.Drawing.Font font = new Font(e.Font.FontFamily, e.Font.Size, FontStyle.Bold);
                Rectangle textBounds = e.Bounds;
                string text = (e.RowIndex + 1).ToString();
                StringFormat formatHeaderText = new StringFormat();
                formatHeaderText.LineAlignment = StringAlignment.Center;
                formatHeaderText.Alignment = StringAlignment.Center;
                e.Graphics.DrawString(text, font, e.Cache.GetSolidBrush(Color.Red), textBounds, formatHeaderText);
            }
            else
            {
                //e.DrawDefault();
            }
        }

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawRowHeader event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also