@bobnoordam

Coloring individual cells or rows in a DX Gridcontrol based on a cell value

Coloring individual cells

This sample hooks into the RowCellStyle event of the Gridview, and evaluates the value of the cell. Depending on the outcome, a background color is assigned to the cell.

private void gridViewQueue_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
    var oView = (GridView)sender;
    if (e.Column.FieldName == "task_stamp")
    {
        Color oBgcolor;
        var dtValue = DateTime.Parse(oView.GetRowCellValue(e.RowHandle, "task_stamp").ToString());
        if (dtValue < DateTime.Now)
        {
            oBgcolor = Color.LightGreen;
        }
        else
        {
            oBgcolor = Color.LightYellow;
        }
  
        if (dtValue.Hour == 20)
        {
            oBgcolor = Color.Yellow;
        }
  
        e.Appearance.BackColor = oBgcolor;
    }
}

Coloring a row

To change the color of the full row, the check on the column is removed, while still querying the content of the specific field in the row. This way, the entire row is colored.

private void gridViewQueue_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
    var oView = (GridView)sender;
    Color oBgcolor;
    var dtValue = DateTime.Parse(oView.GetRowCellValue(e.RowHandle, "task_stamp").ToString());
    if (dtValue < DateTime.Now)
    {
        oBgcolor = Color.LightGreen;
    }
    else
    {
        oBgcolor = Color.LightYellow;
    }
  
    if (dtValue.Hour == 20)
    {
        oBgcolor = Color.Yellow;
    }
    e.Appearance.BackColor = oBgcolor;
}