Friday, May 25, 2018

c# - Check if datagridview cell is null or empty

I have to change the background color of the cells , when their value is string or empty, this is the code i have write similar to other codes here :



for (int rowIndex = 0; rowIndex < dataGridView1.RowCount; rowIndex++)
{
string conte = dataGridView1.Rows[rowIndex].Cells[7].Value.ToString() ;
if (string.IsNullOrEmpty(conte))
{

// dataGridView1.Rows[rowIndex].Cells[7].Style.BackColor = Color.Orange;
}
else
{ dataGridView1.Rows[rowIndex].Cells[7].Style.BackColor = Color.Orange; }
}


the dataset is complete , show me the datagridview populated and the show me this error: enter image description here



How can i fix this?? Have another way to write the code?

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...