Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get C# textbox autocomplete to make suggestions based on contains rather than starts with?

I have a textbox in my C# Windows Forms application that has AutoCompleteMode set to AutoCompleteMode.Suggest, and my content source is a custom source.

My content source is custom, with the following values:

  • Jim Smith
  • Alice Walker
  • Bob Walker
  • Jeremy Smith

The content completion only appears to work by checking if the suggested items "start with" the value in the textbox.

For example:

text=J

Would result in the suggestions:

  • Jim Smith
  • Jeremy Smith

However, if the user types in

text=Walk

There are no results.

How can I get content completion to suggest the following?

  • Alice Walker
  • Bob Walker

Also, my end goal is to have a textbox where individuals can easy start typing email addresses. The content of the autocompletion suggestions will be names + email addresses. For example:

- Jim Smith <[email protected]>
- Alice Walker <[email protected]>
- Bob Walker <[email protected]>
- Jeremy Smith <[email protected]>
like image 722
GreenKiwi Avatar asked Dec 03 '25 09:12

GreenKiwi


1 Answers

This is not possible with the built-in TextBox.

Reading the reference source reveals that the AutoComplete feature calls into the native function SHAutoComplete to do it's job. That one does only prefix matching.

You would have to subclass TextBox and provide your own suggestion feature (or purchase one / find an open source one), to do this.

like image 116
driis Avatar answered Dec 05 '25 14:12

driis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!