VGridControlBase.CustomDrawRowValueCell Event
Enables data cells to be painted manually.
Namespace: DevExpress.XtraVerticalGrid
Assembly: DevExpress.XtraVerticalGrid.v18.1.dll
Declaration
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. |
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. |
The event data class exposes the following methods:
Method | Description |
---|---|
DefaultDraw() | Performs default painting of an element. Inherited from CustomDrawEventArgs. |
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.
Note
The control’s events designed to change the appearance or rendering of control elements must not be used to update cell values or to modify the control’s layout. Any inappropriate operation which causes a layout update, may break the normal control behavior.
Example
The following sample code handles the VGridControlBase.CustomDrawRowValueCell and VGridControlBase.CustomDrawSeparator events to custom paint row cells and cell separators. The CustomDrawSeparatorEventArgs.IsHeaderSeparator property is used to identify whether the cell separator belongs to a row header in order to omit it. Thus, separators contained within the row headers are painted using the default mechanism.
The image below shows the result.
using System.Drawing.Drawing2D;
using DevExpress.XtraVerticalGrid.Events;
private void vGridControl1_CustomDrawSeparator(object sender,
CustomDrawSeparatorEventArgs e) {
if (e.IsHeaderSeparator) return;
switch (e.SeparatorIndex) {
case 0:
// Fills the background.
e.Graphics.FillRectangle(new LinearGradientBrush(e.Bounds,
Color.FromArgb(241, 160, 2),
Color.FromArgb(241, 170, 2), LinearGradientMode.Horizontal), e.Bounds);
// Paints the text which is displayed within the separator.
e.Graphics.DrawString(e.SeparatorString, e.Appearance.Font,
new SolidBrush(Color.DarkBlue), e.Bounds, e.Appearance.GetStringFormat());
break;
case 1:
e.Graphics.FillRectangle(new LinearGradientBrush(e.Bounds,
Color.FromArgb(241, 200, 2),
Color.FromArgb(241, 210, 2), LinearGradientMode.Horizontal), e.Bounds);
e.Graphics.DrawString(e.SeparatorString, e.Appearance.Font,
new SolidBrush(Color.DarkBlue), e.Bounds, e.Appearance.GetStringFormat());
break;
default:
break;
}
e.Handled = true;
}
private void vGridControl1_CustomDrawRowValueCell(object sender,
CustomDrawRowValueCellEventArgs e) {
switch (e.CellIndex){
case 0:
e.Graphics.FillRectangle(new LinearGradientBrush(Rectangle.Inflate(e.Bounds, 1, 1),
Color.FromArgb(241, 130, 2), Color.FromArgb(241, 160, 2),
LinearGradientMode.Horizontal), Rectangle.Inflate(e.Bounds, 1, 1));
// Paints the text which is displayed within the data cell.
e.Graphics.DrawString(e.CellText, e.Appearance.Font,
new SolidBrush(Color.DarkBlue), e.Bounds, e.Appearance.GetStringFormat());
break;
case 1:
e.Graphics.FillRectangle(new LinearGradientBrush(Rectangle.Inflate(e.Bounds, 1, 1),
Color.FromArgb(241, 170, 2), Color.FromArgb(241, 200, 2),
LinearGradientMode.Horizontal), Rectangle.Inflate(e.Bounds, 1, 1));
e.Graphics.DrawString(e.CellText, e.Appearance.Font,
new SolidBrush(Color.DarkBlue), e.Bounds, e.Appearance.GetStringFormat());
break;
case 2:
e.Graphics.FillRectangle(new LinearGradientBrush(Rectangle.Inflate(e.Bounds, 1, 1),
Color.FromArgb(241, 210, 2), Color.FromArgb(241, 240, 2),
LinearGradientMode.Horizontal), Rectangle.Inflate(e.Bounds, 1, 1));
e.Graphics.DrawString(e.CellText, e.Appearance.Font,
new SolidBrush(Color.DarkBlue), e.Bounds, e.Appearance.GetStringFormat());
break;
default:
break;
}
e.Handled = true;
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawRowValueCell 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.