更改网格视图中单元格的颜色,而不是行
本文关键字:颜色 网格 视图 单元格 | 更新日期: 2023-09-27 17:59:18
我有一个显示大量数据的grid view devexpress c#
,我需要根据数据值设置单元格的颜色,如您所见:
private void gridView_RowStyle_1(object sender, RowStyleEventArgs e)
{
if (e.RowHandle >= 0)
{
// Some condition
if (gridView.GetRowCellValue(e.RowHandle, gridView.Columns["Id"]).ToString() == "2")
{
e.Appearance.BackColor = Color.Green;
}
}
}
但是这个函数改变的是整行的颜色而不是单元格。如何设置单元格的颜色?
使用GridView。RowCellStyle事件如下:
void gridView1_RowCellStyle( object sender, RowCellStyleEventArgs e)
{
GridView currentView = sender as GridView;
if (e.Column.FieldName == "Customer" )
{
bool value = Convert.ToBoolean(currentView.GetRowCellValue(e.RowHandle, "Flag_Customer" ));
if (value)
e.Appearance.BackColor = Color.Red;
}
if (e.Column.FieldName == "Vendor" )
{
bool value = Convert.ToBoolean(currentView.GetRowCellValue(e.RowHandle, "Flat_Vendor" ));
if (value)
e.Appearance.BackColor = Color.Red;
}
}