Lavy Lavy - 2 months ago 36
C# Question

How to change background color of a cell in Devexpress Grid?

I have a devexpress xtragrid with 40 columns.
I compare each cell value with other and if it is different then I want to change the cell background color.
I try with GridViewInfo but it only takes the columns that are visible on the screen.But I want to do for all the columns.(Not with RowCellStyle)
Do you have a solution for that?
Thank you!

Answer

Hook onto the RowStyle event of your xtragrid.

private void maintainDataControl_RowStyle(object sender, RowStyleEventArgs e)
{
    if (e.RowHandle >= 0)
    {
        GridView view = sender as GridView;

        // Some condition
        if((string)view.GetRowCellValue(
            e.RowHandle, view.Columns["SomeRow"]).Equals("Some Value"))
        {
            e.Appearance.BackColor = Color.Green;
        }
    }
}