Quote:
Additional information: Index was out of range. Must be non-negative and less than the size of the collection.'
The error clearly says that you are trying to access an
index
in the
collection
which is not present.
In c# most of the collections works on
zero based index
, if you are trying to access the
7th column in the datagridview then you will have to provide the
index
value as
6.
You shall validate as below
foreach (DataGridViewRow dr in dataGridView4.Rows)
{
int targetColumnIndex = 6;
if (dr.Cells.Count > targetColumnIndex)
if (dr.Cells[targetColumnIndex].Value.ToString() == "Processing")
{
dr.Visible = false;
}
}