I've tried -
DataGridView1.DataSource=Nothing
and
DataGridView1.DataSource=Nothing
DataGridView1.Refresh()
and
DataGridView1.RefreshEdit()
None of them works..
I've written a method that sets the DataSource of the DataGridView when executed. but each time i execute it, it replicates the data with new value and appends it to the previous contents of the DGV.. I wanna clear the content and then add the values.. Is that possible?
If the DataGridView is bound to any datasource, you'll have to set the DataGridView's
DataSource
property toNothing
.If the DataGridView is not bound to any data source, this code will do the trick:
Can you not bind the datagridview to an empty collection (instead of null). That do the trick?
I'd probably use this...
to clear out the rows and then rebind.
If the
GridView
(Say the name isgvArchive
) is bound to anyDataSource
, the following will clear it:I found that setting the datasource to null removes the columns. This is what works for me:
c#:
VB:
My DataGridView is also bound to a DataSource and
myDataGridView.Columns.Clear()
worked fine butmyDataGridView.Rows.Clear()
did NOT. Just an FYI for those who have tried.Rows
.