How to remove all rows in a DataGridView

  • Thread starter Thread starter westlakechen
  • Start date Start date
W

westlakechen

Guest
I have a DataGridView that takes data from a textbox that user inputs. Then, a button that lets user save all rows to database. After saving, I want to remove all rows in the DataGridView. However, the DataGridView always keeps one row undeleted. My code is:


private

void button2_Click(object sender, EventArgs e)


{

for (int i = 0; i < dataGridView1.Rows.Count; i++)

{

dataGridView1.Rows.RemoveAt(i);

}

}

What is wrong with my code?

Thanks,


Continue reading...
 
Back
Top