Windows Application Form:

I have a problem with filtering winform datagridview by listbox items (multiselect).
For example: My listbox items have guest name of 'Lim', 'Jack' and 'May'.
I would like to filter my gridview data by these 3 guests.
Which each guest has their own entry.

This is my code and it does not work. Thanks

            switch (cbField.SelectedIndex)
            {
                case 0:
                    Filter = "";
                    break;

                case 1:

                    string FilterStart = "GUEST like '%";
                    string FilterMiddle = "";
                    string FilterEnd = "%'";

                    for (int i = 0; i < lbSearch.Items.Count; i++)
                    {
                        string[] filterEntry = new string[lbSearch.Items.Count];
                        filterEntry[i] = src.searchreplace(lbSearch.Items[i].ToString());

                        FilterMiddle = "or" + filterEntry[i] + "";
                    }

                    Filter = FilterStart + FilterMiddle + FilterEnd;
                    break;
            }

use this

DataTable dtEmploy = new DataTable();
int iiEmpID = Convert.ToInt32(dgvpay_Employ[8, dgvpay_Employ.CurrentRow.Index].Value);
dtEmploy.DefaultView.RowFilter = ("iEmpID ='" + iiEmpID.ToString() + "'");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.