Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,468 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
the application is built in Winfrom C#. and I have a ComboBox containing a list of items
comboBox1.Items.Add("first One ");
comboBox1.Items.Add("second term");
comboBox1.Items.Add("extra one");
I need to search for any word in the list, but currently, the filter is only filtering by the first word.
so if I wrote "One" the result should be two items.
if I wrote "second" the result should be one item
You can so domething like this :
private readonly List<string> items = new List<string> { "first One ", "second term", "extra one" };
private BindingList<string> _bindinglist;
In Form_Load :
_bindinglist = new BindingList<string>(items);
comboBox1.DataSource = _bindinglist;
Test in a Button click
string sKey = "One";
Console.WriteLine(sKey);
var newList = _bindinglist.Where(c => c.IndexOf(sKey, StringComparison.OrdinalIgnoreCase) >= 0);
foreach (var sItem in newList)
{
Console.WriteLine("\t" + sItem);
}
sKey = "second";
Console.WriteLine(sKey);
newList = _bindinglist.Where(c => c.IndexOf(sKey, StringComparison.OrdinalIgnoreCase) >= 0);
foreach (var sItem in newList)
{
Console.WriteLine("\t" + sItem);
}