简体   繁体   中英

C# Textbox Autocomplete: How to provide custom 'matching' function?

I'm using C# TextBox with AutoComplete via a Custom Source of a collection of names, eg John Smith, Mary Jane, etc .. The problem is that if I type in 'John', I do see 'John Smith' in the dropdown. But if I start typing 'Smith', I no longer see 'John Smith' in the dropdown. I'd like to change this, and I think I would have to extend the TextBox class and provide my own function for matching data. I just don't know which TextBox function would need to be overwritten.

Secondly, another related issue I'd like to solve this is: The dropdown text is always left aligned. How can I make it center aligned ?

There is no directly way to do it because AutoCompleteCustomSource only allows prefix matching based on your input string.

From TextBox.AutoCompleteCustomSource Property

Use the AutoCompleteCustomSource, AutoCompleteMode, and AutoCompleteSource properties to create a TextBox that automatically completes input strings by comparing the prefix being entered to the prefixes of all strings in a maintained source.

Best option seems to override your OnTextChanged event of your TextBox . The question below has a good example about it;

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