2
Answers

ComboBox or Textbox AutoComplete on SubString

Yuva Raja

Yuva Raja

Nov 14
451
1

I need a c# (vs-2019) code to get a auto-completion of combobox match any part of string not only start of string. For example (in a vehicle nos populated combo) if the user enters '84'  the combo should suggest / lists all the vehicle numbers those contains the entered number any part of the vehicle numbers, like TN22CC9846, KA13AD8467, TN07AD1846, etc. 

Answers (2)
0
Charles Henington

Charles Henington

1.4k 239 5 Nov 15

public static IEnumerable<string> GetMatches(string[] items, string pattern)
{
    if(items == null || items.Length == 0) yield break;
    foreach(var match in items)
    {
        if (match.Contains(pattern)) yield return match;
    }
}

0
Rajeesh Menoth

Rajeesh Menoth

66 27.1k 2.7m Nov 15

Hi Yuva,

You can go through this article included source code.

https://www.codeproject.com/Tips/631196/ComboBox-with-Suggest-Ability-based-on-Substring-S