0

I want to remove the first row from a datagridview before it loads in the form. What I have at the moment is :

dataGridView1.Rows.Remove(dataGridViewRow[0]);

This doesn't work. Can anyone tell me how I should adapt my code for this to work?

Josh
  • 115
  • 1
  • 3
  • 17

4 Answers4

0

You can try this:

dataGridView1.DeleteRow(dataGridViewRow[0].RowIndex);
randomstudious
  • 122
  • 2
  • 10
0

Perhaps you can try this one and apply it on your form load event.

if(dataGridView1.Rows.Count > 0)
            dataGridView1.Rows.RemoveAt(0);
jegtugado
  • 5,081
  • 1
  • 12
  • 35
0

First, ensure data is loaded. If you're unsure - debug, step through, and ensure there IS a row 0.

Then, try the following:

    dataGridView1.Rows.Remove(dataGridView1.Rows[0]);

Further discussion on row removal here. Might give you some other ideas.

Community
  • 1
  • 1
Kiel
  • 408
  • 4
  • 13
0

Is the datagrid databound to a collection? If so, you could exlude the first element by doing something like this:

List<string> list = GetSomeData();
dataGridView1.DataSource = list.GetRange(1, list.Count-1);
dataGridView1.DataBind();
Gene
  • 36
  • 4