This code will be used to determine wheter a cell value (from a datagridview) is 0, if so it's background color will be red.Code:int countRows = dataGridView1.Rows.Count; for (int i = 0; i < countRows + 1; i++) { if (int.Parse(dataGridView1.Rows[i].Cells[11].Value.ToString()) == 0) { dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red; } }
But i get a NullReferenceException at the red marked line.
So i have two questions:
1. How can i fix this?
2. Is it possible to get data from a cell by using it's columnname? Not like dataGridView1.Rows[i].Cells[11].Value.ToString() since the database column places can be changed.
Thanks in advance.



LinkBack URL
About LinkBacks



