2014-04-10 51 views
2

我想动态地改变某些特定单元格的前景和背景颜色,具体取决于另一个单元格值或事件。如何更改Janus GridEX特定单元格的颜色?

例如,当用户单击单元格时,其背景颜色应为RED。

我的代码是这样的:

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

style1.ForeColor = Color.Red; 

mySpecificCell.FormatStyle = style1; 

它的工作原理,但是当我向下滚动,然后再向上滚动,细胞恢复到原来的颜色的颜色。

我的代码有什么问题?我应该如何克服这一点?

回答

2

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

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

在那里你可以访问整行。

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

2

就像Arthur说的那样,你必须利用Grid的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”访问此行列的名称。

当您想要更改单元格的颜色时,可以替换条件检查。

相关问题