如何改变Janus GridEX特定单元格的颜色?

时间:2014-04-10 10:13:50

标签: janus

我希望动态更改某些特定单元格的前景色和背景色,具体取决于其他单元格值或事件。

例如,当用户点击单元格时,其背面颜色应为红色。

我的代码是这个:

Janus.Windows.GridEX.GridEXFormatStyle style1 = new GridEX.FormatStyle();

style1.ForeColor = Color.Red;

mySpecificCell.FormatStyle = style1;

它可以工作,但当我向下滚动然后再向上滚动时,单元格的颜色会恢复原始颜色。

我的代码有什么问题?我该怎样克服这个?

2 个答案:

答案 0 :(得分:2)

尝试使用Gridex的formattingRow事件来进行自定义格式设置。

为网格上的每一行调用此事件。

您可以访问整行。

这意味着您可以检查某个单元格的值,然后根据第一个单元格格式化另一个单元格。

答案 1 :(得分:2)

就像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”是列的名称。

如果要更改单元格的颜色,可以替换条件检查。

相关问题