windowsforms-440-controls-and-libraries-vertical-grid-appearance-and-custom-painting-appearances-customizing-appearances-of-individual-cells.md
Vertical Grid provides properties to customize the appearance settings of all data cells, focused cell, focused record’s cells, cells that belong to particular editor row or multi-editor row.
If, however, you need to change the appearance settings of individual cells, handle the VGridControlBase.RecordCellStyle event.
This event fires for each cell before it’s painted. The event’s Row and RecordIndex parameters identify the cell currently being processed.
To customize the appearance of cells use the event’s Appearance parameter.
The following example handles the VGridControlBase.RecordCellStyle event to specify appearance settings for the records whose Price field value is greater than $100,000.
using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Rows;
private void vGridControl1_RecordCellStyle(object sender, DevExpress.XtraVerticalGrid.Events.GetCustomRowCellStyleEventArgs e) {
VGridControl vGrid = sender as VGridControl;
RowProperties rowProperties = vGrid.Rows.GetRowPropertiesByFieldName("Price");
if (rowProperties == null) return;
int price = Convert.ToInt32(vGrid.GetCellValue(rowProperties, e.RecordIndex));
if (price < 100000) return;
e.Appearance.BackColor = Color.FromArgb(202, 219, 240);
e.Appearance.FontStyleDelta = FontStyle.Bold;
e.Appearance.ForeColor = Color.FromArgb(61, 128, 189);
}
Imports DevExpress.XtraVerticalGrid
Imports DevExpress.XtraVerticalGrid.Rows
' ...
Private Sub VGridControl1_RecordCellStyle(sender As Object, e As DevExpress.XtraVerticalGrid.Events.GetCustomRowCellStyleEventArgs) Handles VGridControl1.RecordCellStyle
Dim vGrid As VGridControl = TryCast(sender, VGridControl)
Dim rowProperties As RowProperties = vGrid.Rows.GetRowPropertiesByFieldName("Price")
If rowProperties Is Nothing Then Return
Dim price As Integer = Convert.ToInt32(vGrid.GetCellValue(rowProperties, e.RecordIndex))
If price < 100000 Then Return
e.Appearance.BackColor = Color.FromArgb(202, 219, 240)
e.Appearance.FontStyleDelta = FontStyle.Bold
e.Appearance.ForeColor = Color.FromArgb(61, 128, 189)
End Sub
If a target cell resides within a multi-editor row, use the CellIndex event parameter to identify the cell. See the Cells Overview topic for more information.
The following VGridControlBase.RecordCellStyle event handler provides custom appearance settings for cells within a multi-editor row.
private void vGridControl1_RecordCellStyle(object sender, DevExpress.XtraVerticalGrid.Events.GetCustomRowCellStyleEventArgs e) {
if (e.Row != rowMPG) return;
if (e.CellIndex == 0)
e.Appearance.BackColor = Color.FromArgb(194, 207, 180);
else
e.Appearance.BackColor = Color.FromArgb(170, 191, 170);
}
Private Sub VGridControl1_RecordCellStyle(sender As Object, e As DevExpress.XtraVerticalGrid.Events.GetCustomRowCellStyleEventArgs) Handles VGridControl1.RecordCellStyle
If e.Row <> rowMPG Then Return
If e.CellIndex = 0 Then
e.Appearance.BackColor = Color.FromArgb(194, 207, 180)
Else
e.Appearance.BackColor = Color.FromArgb(170, 191, 170)
End If
End Sub
See Also