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

How to: Custom Draw Cells Depending Upon Cell Values

The following code demonstrates how to use the CustomDrawCell event to re-paint cells that belong to the third Grid Column.

using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Base;

CustomDrawCell(gridControl1, gridView1);

public static void CustomDrawCell(GridControl gridControl, GridView gridView) {
    // Handle this event to paint cells manually
    gridView.CustomDrawCell += (s, e) => {
        if (e.Column.VisibleIndex != 2) return;
        e.Cache.FillRectangle(Color.Salmon, e.Bounds);
        e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds);
        e.Handled = true;
    };
}