简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM