SpreadsheetControl.CustomDrawCellBackground Event

Performs custom painting of the cell background.

Namespace: DevExpress.XtraSpreadsheet

Assembly: DevExpress.XtraSpreadsheet.v20.1.dll


public event CustomDrawCellBackgroundEventHandler CustomDrawCellBackground
Public Event CustomDrawCellBackground As CustomDrawCellBackgroundEventHandler

Event Data

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

Property Description
BackColor Gets or sets the background color of the painted cell.
Bounds Returns the bounding rectangle of the drawing area. Inherited from CustomDrawCellEventArgsBase.
Cache Gets an object that serves as the storage for pens, fonts and brushes. Inherited from CustomDrawObjectEventsArgs.
Cell Gets the worksheet cell being painted. Inherited from CustomDrawCellEventArgsBase.
FillBounds Returns the bounding rectangle of the drawing area for painting the cell background. Inherited from CustomDrawCellEventArgsBase.
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.


The CustomDrawCellBackground and CustomDrawCell events fire for each cell in the visible worksheet area and allow you to draw cells in a custom manner.

If you perform custom draw actions, set the CustomDrawObjectEventsArgs.Handled property to true to cancel default painting.

You can also combine your custom painting with the default painting. Call the CustomDrawObjectEventsArgs.DrawDefault method to draw cells with the default painter. Set CustomDrawObjectEventsArgs.Handled to true and use the CustomDrawObjectEventsArgs.Graphics property to display custom elements over default graphics.


Never change cell values or format settings on this event. Any action that causes the control's layout update can lead to an incorrect result or throw an unhandled exception.


In v18.2 and earlier, the CustomDrawCellBackground and CustomDrawCell events fire only for cells that have a value or formatting applied. If you need to restore this behavior, set the EnableLegacyLayoutEngine property to true to switch back to the SpreadsheetControl's legacy layout engine.


The following code paints cells containing a formula (determined by the CellRange.HasFormula value) with a hatched brush. Note that the CustomDrawCellEventArgsBase.FillBounds property instead of the CustomDrawCellEventArgsBase.Bounds property is used to get the rectangle to fill.

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Spreadsheet;
using DevExpress.XtraSpreadsheet;
        void spreadsheetControl1_CustomDrawCellBackground(object sender, CustomDrawCellBackgroundEventArgs e)
            if (e.Cell.HasFormula)
                e.Handled = true;
                System.Drawing.Drawing2D.HatchBrush hBrush = new System.Drawing.Drawing2D.HatchBrush(
See Also