-1

I have a groupbox that contains a listbox that displays a bunch of .txt files. Also in this groupbox is a textbox that I would like to use to search the list of files. I have added some code to my textbox textchange event, but all it does is clear my listbox, and on backspace the listbox is not repopulating with the .txt files it displays? ant help would be greatly apreciated, thanx

private void custsearchbox_TextChanged(object sender, EventArgs e)
    {
        var itemList = custList.Items.Cast<string>().ToList();
        if (itemList.Count > 0)
        {
            //clear the items from the list
            custList.Items.Clear();

            //filter the items and add them to the list
            custList.Items.AddRange(
                itemList.Where(i => i.Contains(custsearchbox.Text)).ToArray());
        }
    }
Simeon EM
  • 1
  • 6

1 Answers1

0

this works:

listsup.Items.Clear();
        Supfile = System.AppDomain.CurrentDomain.BaseDirectory + "data\\Suppliers.txt";
        List<string> proName = new List<string>();
        using (StreamReader rdr = new StreamReader(Supfile))
        {
            string line;
            while ((line = rdr.ReadLine()) != null)
            {
                if (line.ToString().ToLower().Contains(supsearchtxt.Text))
                {
                    string[] val = line.Split(',');
                    listsup.Items.Add(val[0]);
                }
            }
        }
Simeon EM
  • 1
  • 6