nerdalert
nerdalert

Reputation: 461

Filter bound Datagridview with a list (multiple values)

I have a datagridview bound to a MySQL table 'spareparts' using Visual Studio's built in DataSource property. In this datagrid there is a column Part Number. I have a separate list with multiple Part Numbers. Is there a way to filter the datagridview to show all rows where the Part Number matches any Part Number from the list?

I can do it fine for filtering one particular Part Number:

BindingSource bs = new BindingSource();
bs.DataSource = dataGridView1.DataSource;
bs.Filter = "[Part Number] LIKE '%" + mypartno + "%'";
dataGridView1.DataSource = bs;

But I don't know how to do this for multiple part numbers.

Upvotes: 0

Views: 1229

Answers (1)

Ciara
Ciara

Reputation: 394

You may have to loop through your list and build up a string of

OR [Part Number] LIKE [ x ] 

Otherwise if you don't need the wildcards you can use IN instead of LIKE :

"[Part Number] IN ( 'x', 'y', 'z')"

Upvotes: 1

Related Questions