3
Answers

what is my mistake?

Ask a question
Vikas Ahlawat

Vikas Ahlawat

14y
1.9k
1
for (int i = 2; i <= SCdataGridView1.Rows.Count;i++)
            {
                int malecount = 0;
                if (SCdataGridView1.Rows[i].Cells[8].Value.ToString() == "Male") //here the error occure because I put here i
                {
                    malecount = malecount + 1;
                    SClabel6.Text = malecount.ToString();
                }
            }

error is
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Answers (3)