FIlter DataGridView with datasource dictionary.values

I am familiar with filtering rows in dataTable using DataView.

I would like to filter a datagridview that has a datasource based on dictionary values. So it doesn't convert to datatable.

dataGridView1.DataSource = _someDict.values.where(what you need).ToList();


For filtering, I wanted to use something like this: Filter DataGridView (Sami's answer) or Filtering DataGridView without changing the data source (Brad Bruce and Joe Sisk's answers)

casting data source into dataTable like:

var dt = (dataGridView1.DataSource as DataTable);


returns null.

So, I tried using the bind file.

_bindingSource.DataSource = _someDict.values.where(what you need).ToList();
dataGridView1.DataSource = _bindingSource;


The DataGridView is populated with the correct data. But when I try to filter like this:

_bindingSource.Filter= "MyColumn like '%" + textBox1.Text + "%'";


the lines are not filtered and I can still see all the lines. Even after dataGridView1.DataSource = _bindingSource; dataGridView1.Refresh ();

Any suggestions? I know how to create data from a list (I have an extension for that), but I prefer to just bind the dictionary values ​​to the bindingSource or dataGridView. Respectfully,



source to share

All Articles