VGridControlBase.CustomDrawRowValueCell Event

Enables data cells to be painted manually.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v20.1.dll

Declaration

public event CustomDrawRowValueCellEventHandler CustomDrawRowValueCell
Public Event CustomDrawRowValueCell As CustomDrawRowValueCellEventHandler

Event Data

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

Property Description
Appearance Gets the painted element's appearance settings. Inherited from CustomDrawEventArgs.
Bounds Gets a value specifying limits for the drawing area. Inherited from CustomDrawEventArgs.
Cache Gets an object which specifies the storage for the most used pens, fonts and brushes. Inherited from CustomDrawEventArgs.
CellIndex Gets the index of the painted row data cell.
CellText Gets or sets the text displayed in the painted cell.
CellValue Gets the painted cell's value.
Enabled Gets a value indicating whether end-users can modify cell values within the painted row.
Graphics Gets an object used to paint. Inherited from CustomDrawEventArgs.
Handled Gets or sets a value specifying whether an event was handled, if handled, default actions are not required. Inherited from CustomDrawEventArgs.
IsRightToLeft Gets a value indicating whether the VGridControl's elements are aligned to support locales using right-to-left fonts. Inherited from CustomDrawEventArgs.
Item Returns the RepositoryItem for which the VGridControlBase.CustomDrawRowValueCell event was raised.
ObjectArgs Gets an object containing information about the painted element. Inherited from CustomDrawEventArgs.
Painter Gets the painter object that provides the default element's painting mechanism. Inherited from CustomDrawEventArgs.
Properties Provides properties specific to the row being custom painted. Inherited from CustomDrawRowEventArgs.
RecordIndex Gets the index of the painted cell's record.
Row Gets the row whose element is to be drawn. Inherited from CustomDrawRowEventArgs.
RowValueInfo Gets information on the row value view.

Remarks

The CustomDrawRowValueCell event is raised before a data cell is painted. The cell is identified by the event parameter's CustomDrawRowEventArgs.Row, CustomDrawRowValueCellEventArgs.RecordIndex and CustomDrawRowValueCellEventArgs.CellIndex properties.

The CustomDrawRowValueCell event can be used for two purposes:

  • To manually paint all or only particular data cells. Note that you need to set the CustomDrawEventArgs.Handled parameter to true to indicate that the default painting is not required for the cell.
  • Change the cell's settings (text, appearance, etc.) and leave the CustomDrawEventArgs.Handled parameter set to false. This will paint cells using the default mechanism but with modified settings.
IMPORTANT

Do not change cell values, modify the control's layout, or change the control's object model in the events used for custom control painting. Actions that update the layout can cause the control to malfunction.

Examples

The following sample code handles the VGridControlBase.CustomDrawRowHeaderCell, VGridControlBase.CustomDrawRowValueCell and VGridControlBase.CustomDrawSeparator events to custom paint cells in a multi-editor row.

using DevExpress.XtraVerticalGrid.Rows;

using System.Drawing.Drawing2D;
using DevExpress.XtraVerticalGrid.Events;

private void Form1_Load(object sender, EventArgs e) {
    vGridControl1.OptionsView.ShowRootLevelIndent = false;
    MultiEditorRow meRow = (vGridControl1.Rows[0] as MultiEditorRow);
    if (meRow != null) {
        meRow.SeparatorKind = SeparatorKind.String;
        meRow.SeparatorString = "/";
    }
}

Font fontRegular = new Font("Tahoma", 10);
Font fontBold = new Font("Tahoma", 10, FontStyle.Bold);

private void vGridControl1_CustomDrawSeparator(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawSeparatorEventArgs e) {
   Font font = fontRegular;
    Brush brush = Brushes.Orange;
    if(e.IsHeaderSeparator) {
        font = fontBold;
        brush = Brushes.LightGray;
    }
    e.Cache.FillRectangle(brush, e.Bounds);
    e.Cache.DrawString("/", font, Brushes.DarkBlue, e.Bounds, e.Appearance.GetStringFormat());
    e.Handled = true;
}

private void vGridControl1_CustomDrawRowValueCell(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawRowValueCellEventArgs e) {
    e.Cache.FillRectangle(Brushes.Orange, Rectangle.Inflate(e.Bounds, 1, 1));
    e.Cache.DrawString(e.CellText, e.Appearance.Font, Brushes.Black, e.Bounds, e.Appearance.GetStringFormat());
    e.Handled = true;
}

private void vGridControl1_CustomDrawRowHeaderCell(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawRowHeaderCellEventArgs e) {
    Rectangle rect = Rectangle.Inflate(e.Bounds, 1, 1);
    Rectangle rectText = Rectangle.Inflate(e.Bounds, -2, 0);
    e.Cache.FillRectangle(Brushes.LightGray, rect);
    e.Cache.DrawString(e.Caption, e.Appearance.Font, Brushes.Black, rectText, e.Appearance.GetStringFormat());
    e.Handled = true;
}
See Also