0

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;
            }
2
Contributors
1
Reply
19
Views
4 Years
Discussion Span
Last Post by uis
0

use this

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.