Customizing Appearances of Individual Cells

  • 2 minutes to read

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.

Example - Customize the Appearance of Records

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.Font = new Font(e.Appearance.Font, FontStyle.Bold);
    e.Appearance.ForeColor = Color.FromArgb(61, 128, 189);
}

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.

Example - Customize the Appearance of Cells in a Multi-Editor Row

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);
}
See Also