Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocomplete [contains instead of starting with] in winform TextBox

Tags:

c#

winforms

// [in designer] textBoxInContext.AutoCompleteMode = Suggest
// [in designer] textBoxInContext.AutoCompleteSource = CustomSource
AutoCompleteStringCollection autoComplete = new AutoCompleteStringCollection();
autoComplete.AddRange(myArrayofStrings);
textBoxInContext.AutoCompleteCustomSource = autoComplete;

I have this code which works well as documented in MSDN.

Problem: if user types "PS" it shows all the string starting with "PS"; I would like to display all the strings containing "PS"

Any pointers ?

like image 776
karephul Avatar asked Nov 02 '11 18:11

karephul


1 Answers

If you don't find another way, I suggest doing it manually:

  1. Use a combobox with no items(you'll fill them manually later).
  2. Have a string array with your possible suggestions.
  3. At the combobox.TextChanged or KeyUp event take its text and compare it to your string array whichever way you want and, after clearing the combobox.Items, add the found results to the combobox.Items and make sure to set the DroppedDown property to true if you have found suggestions.
like image 63
David Avatar answered Oct 21 '22 22:10

David