Reputation: 63377
This is not easy, as far as I know, I can only filter rows in my DataGridView when it's DataSource is assigned for a DataTable (use DefaultView.RowFilter) or a BindingSource (use Filter). But my DataGridView DataSource is like this:
myDataGridView.DataSource = myDataSet;
myDataGridView.DataMember = "myTableName";
//filtering rows using myDataSet.Tables["myTableName"].RowFilter = "..." doesn't work.
myDataSet is alreadly bound to some controls on my form and I don't want to rebind it when myDataGridView's DataSource changes.
I don't want to set my DataGridView's DataSource like this:
myDataGridView.DataSource = myDataTable;
//then use myDataTable.DefaultView.RowFilter = "...";
//or
BindingSource bs = new BindingSource(myDataSet, "myTableName");
myDataGridView.DataSource = bs;
//then use bs.Filter = "..."
I just want my DataGridView datasource as in the first code, how can I filter rows for it in that context? Please be sure it works and notice about what I mentioned here.
Your help would be highly appreciated!
Thank you.
Upvotes: 1
Views: 7161
Reputation: 5101
Try myDataSet.Tables["myTableName"].DefaultView.RowFilter = "..."
if that doesn't float your boat then this from another SO thread.
(dataGridViewFields.DataSource as DataTable).DefaultView.RowFilter = string.Format("Field = '{0}'", textBoxFilter.Text);
Upvotes: 1