Hello,
I want with a condition : * all rows have bool_badge =0 : color with RED * all rows have bool_badge=1 : color with ForestGreen
I have a code Correct BUT just when i click for a cell specific:
But i have result just when i click in a specific ROW
But I want when i execute my application , the test begin if bool_badge 0 or 1, and i have for all the gridview : color RED or ForestGreen ,
I try this code:
But i have ERROR!
in this ligne :
string valeur = dataGridView1[2, i].Value.ToString();
The NullReferenceException was unhandled
Object reference not set to an instance of an object
How can i fix it?
Very thanks,
What I have tried:
* Code for just a specific ROW:
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
int row = this.dataGridView1.CurrentCell.RowIndex;
string valeur = dataGridView1[2, row].Value.ToString();
if (valeur == "0")
{
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
}
else
{
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.ForestGreen;
}
}
* My try code:
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
string valeur = dataGridView1[2, i].Value.ToString();
if (valeur == "0")
{
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
}
else
{
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.ForestGreen;