Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to remove all rows in a DataGridView

$
0
0

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,


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>