[英]How to change cell backcolor in devexpress grid by cell value?
I'm trying to solve how to change cell backcolor by it's value ? 我正在尝试解决如何通过其值更改单元背景色? for example, column name - Colors, and columns rows value is color name - red, yellow, blue and etc. So I want to know how to change cell backcolor by value.
例如,列名称-颜色,而列行的值是颜色名称-红色,黄色,蓝色等。因此,我想知道如何通过值更改单元格背景色。 If cell value is - red, then I want cell backcolor be red.
如果单元格值为-红色,那么我希望单元格背景色为红色。
Thanks 谢谢
You can use GridView.CustomDrawCell
event. 您可以使用
GridView.CustomDrawCell
事件。 You can get the column from e.Column
property, and you can get the cell value from e.CellValue
. 您可以从
e.Column
属性获取列,也可以从e.CellValue
获取单元格值。
Here is example: 这是示例:
private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
if (e.Column.FieldName == "Colors")
try
{
e.Appearance.BackColor = Color.FromName(e.CellValue.ToString());
e.Appearance.Options.UseBackColor = true;
}
catch { }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.