How to delete selected rows in datagridview efficiently?

Peter King

Member
Joined
Sep 11, 2006
Messages
15
Programming Experience
Beginner
Hi, there,

I have a DataGridView with data source from a DataTable. The DataTable is generated from a text file (not bound to any database), and contains roughly 500000 rows.

I want the user to select some rows, and delete those selected rows by clicking a button. The problem is that if the user select many rows to delete, it takes ages (say, 10 minutes) to complete the delete action. I use the following code.

Dim deleteRows As DataGridViewSelectedRowCollection = _
DataGridView1.SelectedRows
Dim row As DataGridViewRow
For Each row In deleteRows
DataGridView1.Rows.Remove(row)
Next

I cannot figure out a more efficient method to do the deletion.

Can anyone help?

Thanks a lot!

P
 
Back
Top