I used this code to change rows' color with a condition but the code doesn't work! I don't know why, I have an error :
An unhandled exception of type System.NullReferenceException' occurred in db(name of the project).exe
when I arrive at "color= dataGridView1.Rows...."
What should I do?
while (true)
{
color = dataGridView1[2, rowindex].Value.ToString();
if (color == "IDLE")
{
dataGridView1.Rows[rowindex].DefaultCellStyle.BackColor = Color.Orange;
}
if (color == "ACTIVE")
{ dataGridView1.Rows[rowindex].DefaultCellStyle.BackColor = Color.Green; }
if (color == "MAINTENANCE")
{ dataGridView1.Rows[rowindex].DefaultCellStyle.BackColor = Color.Purple; }
if (color == "DISMISSED")
{ dataGridView1.Rows[rowindex].DefaultCellStyle.BackColor = Color.Red; }
if (color == null)
{ break; }
rowindex++;
}