Datagrid Row -change color based on logic

Answered
0
0

How can I change the color of an entire row via code?

I tried

row.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;

row.DefaultCellStyle.BackColor = System.Drawing.Color.Red;

 

Neither seems to affect the row at all.

  • You must to post comments
Best Answer
1
1

Hi Edmond,

WJ-9133 is fixed in the latest Wisej build (1.5.12)

Best regards
Frank

  • You must to post comments
0
0

Row color is not change    for   1.5.16
foreach (DataGridViewRow row in dataGridView1.Rows)
if (Convert.ToString(row.Cells[1].Value) == “C”)
{
row.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
}
else
{
row.DefaultCellStyle.BackColor = System.Drawing.Color.GreenYellow;
}

dataGridView1.Update();
Application.Update(this);

  • Luca (ITG)
    Cannot reproduce. There is no need to call Update. Can you attach a test case? If you run the code in the snippet after assigning the DataSource the rows are recreated when the datagrid is created and made visible (this is standard behavior, you need to use the DataBindingComplete event or bind after the grid has been fully created.
  • You must to post comments
1
0

So far this fix seems to work.

  • You must to post comments
0
0

Hi there,

You’ll see the colour changes if you refresh the page.

There’s a workaround as follows:

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
byte j;
for(j=0;j<dataGridView1.ColumnCount;j++)
{
dataGridView1.Rows[e.RowIndex].Cells[j].Style.ForeColor = System.Drawing.Color.Red;
}
}

  • You must to post comments
0
0

Hi Edmond,

thanks for putting together that sample. It helped us to reproduce the problem.
It´s logged as WJ-9133 and a fix will be included in the next Wisej release.

Best regards
Frank

  • You must to post comments
0
0

Test case attached

Attachment
  • You must to post comments
0
0

Please post a reproducible test case. It depends on when you set the style, the row you are referring to may not exist anymore.

  • edmond girardi
    I’ll try to put together a sample – but the row is visible in the data grid – basically I want to change the font color or the background color of the entire row to show that the user has already viewed the row after the double click on it to open up a details window containing more info.
  • edmond girardi
    Did not get a chance to put together a sample yet – but here is what I’m doing -oddly enough it ALWAYS seems to work when i double click the first column of the row, any other column – no luck: private void dgv_Results_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { // Set Row Color to indicate it was viewed dgv_Results.Rows[e.RowIndex].DefaultCellStyle.ForeColor = System.Drawing.Color.Red; } } i checked with the debugger – double clicking every cell in the row returns the same RowIndex – but double clicking only the first cell actually makes the text of the entire row red
  • edmond girardi
    Test case attached. Double Click on any row – if you click in first cell – font for entire row changes to Red – double click any other cell – no color changed -however – the event does fire as i set a break point in the debugger.
  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.