Filter ListBox items based upon textbox from OnKeyUp?

谁说我不能喝 提交于 2019-12-06 12:45:30

Here is a sample solution

private void textBox1_TextChanged(object sender, EventArgs e)
  {
      listBox1.Items.Clear();
      List<String> lst = new List<string> {"2342","3434","2332","3224"};
      listBox1.Items.AddRange(lst.Where(X => X.StartsWith(textBox1.Text)).ToArray());

  }

And one more

listBox1.Items.AddRange(listBox1.Items.Cast<String>().Where(X=>X.StartsWith(textBox1.Text)).ToArray());
stuartd

There's a jQuery implementation of this in Jquery Listbox / Textbox filter which should get you started, even if you don't want to use jQuery.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!