mardi 25 septembre 2018

C# If statement based on conditional Gridview cell color

Apologies if this is trivial, but I am trying to switch from VB to C#. I'm trying to change the background color of a Datagridview cell conditional on the background color of another cell. For example, if row(0), cell(0) is "red", then make row(1), cell(1) "green".

In VB (which works) I use:

If GridView1.Rows(0).Cells(0).BackColor = Drawing.Color.Red Then
GridView1.Rows(4).Cells(3).BackColor = Drawing.Color.Red
End If

But in C#:

if (GridView1.Rows[0].Cells[0].BackColor = System.Drawing.Color.Red)
{
GridView1.Rows[4].Cells[3].BackColor = System.Drawing.Color.Red;
}
else
{
}

Instead I receive the error: "Cannot implicitly convert type 'system.drawing.color' to 'bool'. I understand that red is not true/false but I don't understand why it's being interpreted as a boolean variable. Any help would be appreciated!

Thanks :)

Aucun commentaire:

Enregistrer un commentaire