I've datagrid view in form which is dynamically populating data using DataView technique through this code:
DV = New DataView()
DV.Table = ds.Tables("rsSearch")
FlxSearch.DataSource = DV
but i want to remove previous column structure. similarly, when i call this grid with same dataset
this is happening:
I've tried many solutions of clearing and disposing DGV and DataView but couldn't achieve desired result. any suggestions for how to remove previously filled column structure when loading new Data?
yourDataGridView.Columns.Clear()
DataView
is probably pointless. Just bind theDataTable
. EveryDataTable
already has aDataView
associated with it, accessible via itsDefaultView
property. When you bind aDataTable
, that's where the data comes from anyway. That's how you are able to click a grid column header to sort. You only need to create aDataView
explicitly if you want multiple views of the same table.FlxSearch.DataSource = ds.Tables("rsSearch")
. When you change the DataTable, the DGV's Column structure follows suite. Unless you have added those Columns in the Designer. Since you want to change DataTable, thus Column Names, dynamically, remove the Columns from the Designer.ds.Tables("rsSearch").DefaultView.RowFilter = "The Filter"
. OrDirectCast(FlxSearch.DataSource, DataTable).DefaultView.RowFilter = "The Filter"
. Same object, same filter, same result.