我想根据另一个单元格值或事件动态更改某些特定单元格的前景色和背景色。
例如,当用户点击单元格时,它的背景颜色应该是红色。
我的代码是这样的:
Janus.Windows.GridEX.GridEXFormatStyle style1 = new GridEX.FormatStyle();
style1.ForeColor = Color.Red;
mySpecificCell.FormatStyle = style1;
它有效,但是当我向下滚动然后再次向上滚动时,单元格的颜色恢复为原始颜色。
我的代码有什么问题?我应该如何克服这个问题?
最佳答案
正如 Arthur 所说,您必须利用网格的 FormattingRow 事件。
这是一个示例代码:
private void grd_FormattingRow(object sender, RowLoadEventArgs e)
{
if (e.Row.Cells["ColumnName"].Value == someValue) // a condition to determine when to change the color of the cell, you can put your own condition
e.Row.Cells["ColumnName"].FormatStyle = new GridEXFormatStyle() { BackColor = Color.Red };
}
格式化行将针对正在显示的网格中的每一行触发,您可以使用 e.Row 访问该行
"ColumnName"是列的名称。
当你想改变单元格的颜色时,你可以将条件替换为ocheck。
关于janus - 如何更改 Janus GridEX 特定单元格的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22985059/