![](/img/trans.png)
[英]move Rows up and down or change row color if the row cell value are the same gridview devexpress winforms c#?
[英]Change the color of a cell in gridview devexpress not row
我有一个显示大量数据的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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.