如何在Devexpress Grid中更改单元格的背景颜色?

时间:2012-06-29 13:45:09

标签: c# grid devexpress xtragrid

我有一个40列的devexpress xtragrid。 我将每个单元格值与其他单元格进行比较,如果它不同,那么我想更改单元格背景颜色。 我尝试使用GridViewInfo,但它只占用屏幕上可见的列。但我想对所有列进行。(不使用RowCellStyle) 你有解决方案吗? 谢谢!

3 个答案:

答案 0 :(得分:6)

您需要处理GridView的 CustomDrawCell ,这里有一段代码,根据其他列valoe(年龄列)更改Name列的颜色

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);
        }
    }
祝你好运

答案 1 :(得分:4)

挂钩到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;
        }
    }
}

答案 2 :(得分:2)

您是否尝试过Xtragrid Format conditions?

相关问题