简体   繁体   English

如何使用DataSet作为数据源过滤DataGridView

[英]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. 我从数据库中检索数据,并使用TableAdapter将其填充到DataSet中。

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. 我的Datagridview就是这样,我可以从原始数据集中删除和添加列。

I want to filter the DataGridView, so I use the following: 我想过滤DataGridView,所以我使用以下内容:

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. 这会将所有列带回到Datagridview中。 I don't want it to alter the columns that are currently being displayed in my Datagridview. 我不希望它更改Datagridview中当前显示的列。 Can't I some how get the current view of my Datagridview? 我无法了解如何获取Datagridview的当前视图吗?

Thanks in advance! 提前致谢!

Set the DataGridView.AutoGenerateColumns property to False . DataGridView.AutoGenerateColumns属性设置为False

This will prevent the DGV from automatically generate columns when the data source and/or data member is changed. 当更改数据源和/或数据成员时,这将防止DGV自动生成列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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