C# 如何更改Devexpress网格中单元格的背景色?

C# 如何更改Devexpress网格中单元格的背景色?,c#,grid,devexpress,xtragrid,C#,Grid,Devexpress,Xtragrid,我有一个包含40列的devexpress xtragrid。 我将每个单元格的值与其他单元格的值进行比较,如果它不同,那么我想更改单元格的背景色。 我尝试使用GridViewInfo,但它只接受屏幕上可见的列。但我想对所有列执行此操作。(不使用RowCellStyle) 你有解决办法吗? 谢谢大家! 挂接xtragrid的RowStyle事件 private void maintainDataControl_RowStyle(object sender, RowStyleEventArgs e)

我有一个包含40列的devexpress xtragrid。 我将每个单元格的值与其他单元格的值进行比较,如果它不同,那么我想更改单元格的背景色。 我尝试使用GridViewInfo,但它只接受屏幕上可见的列。但我想对所有列执行此操作。(不使用RowCellStyle) 你有解决办法吗?
谢谢大家!

挂接xtragrid的RowStyle事件

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;
        }
    }
}

您需要处理GridView的CustomDrawCell,下面是一段代码,根据另一列valoe(年龄列)更改Name列的颜色

private void gridView\u CustomDrawCell(对象发送方,RowCellCustomDrawEventArgs e)
{
if(e.Column==colName)
{
var age=Convert.ToInt32(gridView.GetRowCellValue(e.RowHandle,colAge));
if(年龄<18岁)
e、 外观.BackColor=Color.FromArgb(0xFE,0xDF,0x98);
其他的
e、 外观.BackColor=Color.FromArgb(0xD2,0xFD,0x91);
}
}

祝您好运

您是否尝试过

比较功能位于按钮上。我如何调用RowStyle事件?您不能在按钮单击事件上执行此操作。您必须处理
RowStyle
CustomDrawCell
。将它们的条件放在那里,并在对按钮上的数据进行更改后使网格无效。。
private void gridView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
    {
        if (e.Column == colName)
        {
            var age = Convert.ToInt32(gridView.GetRowCellValue(e.RowHandle, colAge));
            if (age < 18)
                e.Appearance.BackColor = Color.FromArgb(0xFE, 0xDF, 0x98);
            else
                e.Appearance.BackColor = Color.FromArgb(0xD2, 0xFD, 0x91);
        }
    }