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



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

您需要处理 GridView 的 CustomDrawCell,下面是一个代码片段,用于根据其他列 valoe(年龄列)更改"名称"列的颜色

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

祝你好运

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

你试过Xtragrid格式条件吗?

最新更新