Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
It looks like a newbie's question but it's not actually.

The problem is I just want my DataGridView's DataSource like this:

C#
myDataGridView.DataSource = myDataSet;
myDataGridView.DataMember = "myTableName";
//however filtering its rows like this doesn't work:
myDataSet.Tables["myTableName"].DefaultView.RowFilter = "...";


Plus, myDataSet is already bound to some controls on my form and I don't want to rebind it in case that myDataGridView's DataSource changes.

If that condition is not the case, I would use the following and can filter rows OK:

C#
//choice 1
myDataGridView.DataSource = myDataTable;
//then filter rows like this:
myDataTable.DefaultView.RowFilter = "...";

//choice 2
BindingSource bs = new BindingSource(myDataSet, "myTableName");
myDataGridView.DataSource = bs;
//then filter rows like this:
bs.Filter = "...";


I just want it as in the first code snippet. How can I filter its rows in that case?

Thank you in advance for your help!
Posted
Updated 23-Apr-13 0:10am
v2

1 solution

You can't filter rows without a BindingSource unless you reload the data source and change the actual rows it contains - that is why you use a Binding Source in the first place: to act as an intermediary which can be filtered.
 
Share this answer
 
Comments
supernorb 23-Apr-13 7:47am    
Really? Well, it looks like that, I also think it can't be done that way (but not sure) and that's why BindingSource exists. Thanks!

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