Click here to Skip to main content
15,914,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

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 :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900