从第二种形式过滤datagridview [英] Filtering a datagridview from a second form

查看:101
本文介绍了从第二种形式过滤datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我完全是学习VB2010的初学者,并且有一个项目需要打开一个放在表格B上的datagridview.我已经将此Datagrid附加到数据源,但是现在我需要在运行时过滤生成的数据集.我有表格A收集特定条件,并且需要将该条件作为我的dataview数据集的过滤器进行传递.

有人可以请帮助吗?

非常感谢.

Hello all,

I am totally a beginner learning VB2010 and have a project where I need to open a datagridview which I have placed on form B. I have already attached this datagrid to a datasource but now I need to filter the resulting dataset in runtime. I have Form A collecting the specific criteria and need to pass that criteria as a filter for my dataview dataset.

Can someone please please help???

Thanks a lot.

推荐答案

实际上,我不久前问了一个有关过滤的问题.虽然与您的问题根本不相似,但我确实指出了BindingSource.Filter属性.
您可以将DataSet/Table绑定到 BindingSource [ ^ ],然后使用过滤器属性 [ IBindingListView界面 [ ^ ].幸运的是,在使用数据集时,您不必自己实现这一点.如您所见, DataView [
Actually, I asked a question about filtering not long ago. While not at all similiar to your question I did point out the BindingSource.Filter Property.
You could bind your DataSet/Table to a BindingSource[^] and use the Filter Property[^]. Note that filtering this way is only possible when the DataSource Implements the IBindingListView Interface[^]. Luckily, when working with DataSets you do not have to Implement this yourself. As you can see the DataView[^] already Implements this. My problem was that this Interface was not Implemented by my DataSource (a List(Of T)). Luckily you do not seem to have this problem :)
So much for the background information.

So, to sum this up:
Assign a DataSet/Table to the DataSource Property of a BindingSource.
Assign the BindingSource to the DataSource Property of your DataGridView.
Set the Filter Property of the BindingSource (an SQL-like String).
You might have to call BindingSource.ResetBindings(False).

Take care that this means, when for example fetching data from a database, you first have to get the entire dataset and then filter.
Filtering the dataset that is initially retreived is not so easy :)


这篇关于从第二种形式过滤datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆