我有一个包含40列的DevExpress XtraGrid表格。我需要比较每个单元格的值,如果不同则改变单元格的背景颜色。我尝试使用GridViewInfo,但它只能获取屏幕上可见的列。但我想对所有列执行此操作(而不是使用RowCellStyle)。请问您有解决方案吗?谢谢!
我有一个包含40列的DevExpress XtraGrid表格。我需要比较每个单元格的值,如果不同则改变单元格的背景颜色。我尝试使用GridViewInfo,但它只能获取屏幕上可见的列。但我想对所有列执行此操作(而不是使用RowCellStyle)。请问您有解决方案吗?谢谢!
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;
}
}
}
RowStyle
或者CustomDrawCell
。将它们的条件放在那里,然后在对数据进行更改后,简单地使网格无效即可。 - Niranjan Singh