2

I Want to change the foreground and background color of some specific cells dynamically, depending to another cell values or events.

For example, when The user clicks the cell, Its back color should be RED.

My code is This:

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

style1.ForeColor = Color.Red;

mySpecificCell.FormatStyle = style1;

It works, but when I scroll down and then scroll up again, the color of cell returns to original color.

What is the problem with my code? How should I overcome this?

Adel Khayata
  • 2,717
  • 10
  • 28
  • 46

2 Answers2

4

Like Arthur said, you have to utilize the FormattingRow event of the grid.

This is a sample code:

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 };

}

The Formatting Row will fire for each row in the grid that is being displayed and you can access this row using e.Row

"ColumnName" is the name of the column.

You can replace the condition t ocheck when you want to change the color of the cell.

Adel Khayata
  • 2,717
  • 10
  • 28
  • 46
2

Try using the Gridex's formattingRow event to do your customized formatting.

This event is called for every row on the grid.

There you have access to the full row.

That means you could check the value of some cell and then format another cell based on the first.

Adel Khayata
  • 2,717
  • 10
  • 28
  • 46
Arthur Rizzo
  • 1,337
  • 15
  • 30