I want to check if a particular cell of a datagridview has a particular value. So I made a double "for" loop to check through columns and rows. And there is the NullReferenceException thrown while checking using "if". Can someone please help me? What's more, if I put "try & catch" those cells ARE chosen and colored (I want them to be colored). I don't get it.
Here's the code:
for (int column = 0; column < 7; column++)
{
for (int row = 0; row < 6; row++)
{
if (dataGridView1.Rows[row].Cells[column].Value.ToString() == data.Day.ToString())// EXCEPTION
{
dataGridView1[column, row].Style.BackColor = Color.LightGreen;
}
}
}