简体   繁体   中英

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 <jsmith@mycorp.com>
- Alice Walker <alice@some.email.com>
- Bob Walker <bob.walker@mycorp.com>
- Jeremy Smith <jeremys@foo.com>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM