Oscar Marquez

Hi! how can i clear all the cells of the datagridview (when are bounded) this is my scenario:

i use a DataGridView to register products for a sale ticket, but if i decide cancel the ticket i have to clear the products, there is an event, datagridview.clear but it returns "the list cannot be cleared" something like that




Re: Windows Forms Data Controls and Databinding clearing a datagridview

paulains

To clear a DataGridView, clear the data to which the DataGridView is bounded.  If that's a DataTable, for instance, it has a Clear() function of its own.



Re: Windows Forms Data Controls and Databinding clearing a datagridview

Logifire

If you set the RowCount property to 0, all rows will be removed from the DataGridView. This is equivalent to calling the DataGridViewRowCollection.Clear method.



Re: Windows Forms Data Controls and Databinding clearing a datagridview

Milo Minderbinder

I tried the above two suggestions, but neither worked. I tried setting the DataSource of the DataGridView to null and that worked.

dataGridView.DataSource = null;