1 Attachment(s)
Rows collection cannot be programmatically cleared -- Error
Hello All ......
I Have Bound DataGridView and i tried to clear it before get record ihave tried :
And
Code:
DGV.Datasorce=Nothing
And
None Or Then Works iand iam getting this error
Rows collection cannot be programmatically cleared when the DataGridView control is data-bound to anything else than an IBindingList that supports change notification and allows deletion.
Attachment 156501
Re: Rows collection cannot be programmatically cleared -- Error
Right... so as long as it is bound, you cannot clear the rows. So you have to do two things. Unbind the DGV, then clear the rows.
-tg
Re: Rows collection cannot be programmatically cleared -- Error
Got it ...
Code:
DGV.DataSource = Nothing
DGV.Rows.Clear()
Thanks For Help
Re: Rows collection cannot be programmatically cleared -- Error
If you set the DataSource to Nothing then that should remove the rows automatically. The question is whether setting the DataSource to Nothing is the correct option. It may actually be more appropriate that the grid remains bound and you remove/delete all the rows/items in the data source. We can't really say based on the information provided. Looking at your screenshot though, it looks like you're doing something weird. Why are you adding rows to the grid directly from a DataTable? Why aren't you simply binding that DataTable to the grid?