Search code examples
vb.netdatagridviewfilterdatasetrowfilter

How to Filter DataGridView with DataSet as DataSource


Need some help.

I retrieve data from a Database and fill it into a DataSet using a TableAdapter.

MyTableAdapter.Fill(MyDataSet, "Table1")
DataGridView1.DataSource=MyDataSet
DataGridView1.DataMember="Table1"

My Datagridview is such, that I can remove and add columns from the original dataset.

I want to filter the DataGridView, so I use the following:

Dim dv As DataView
dv = MyDataSet.Tables("Table1").DefaultView
dv.RowFilter = "day >= '05Jan15'"
DataGridView1.DataSource = dv

Problem:

This brings back ALL columns into the Datagridview. I don't want it to alter the columns that are currently being displayed in my Datagridview. Can't I some how get the current view of my Datagridview?

Thanks in advance!


Solution

  • Set the DataGridView.AutoGenerateColumns property to False.

    This will prevent the DGV from automatically generate columns when the data source and/or data member is changed.