How to clear DataGridView?

dranko

Member
Joined
Apr 16, 2006
Messages
16
Programming Experience
Beginner
I have some texboxes od form, bound to DataTable1 and
DataGridView is bound to DataTable2. There is relation between DataTable1(Master) and DataTable2(Details).
How to clear all rows from DataGridView?

I've tried this:
VB.NET:
For Each row As DataGridViewRow In DataGridView1.Rows
      If DataGridView1.CurrentRow IsNot Nothing Then
         DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
      End If
Next
This works when it is 1 or 2 rows in DataGridView, but when there is 3 or more rows
it throws exception:
"System.ArgumentException: DataGridViewComboBoxCell value is not valid."

Edit: One of columns in DataGridView is DataGridViewComboBoxColumn which DataSource is the third DataTable(lookuptable).
 
Last edited:
Back
Top