开发者

ComboBox AutoComplete Custom Capabilities

开发者 https://www.devze.com 2022-12-12 07:25 出处:网络
How can I extend the AutoComplete feature of a WinForm ComboBox to, for example, find matches of items usin开发者_高级运维g a regular expression or for simplicity to find items that contains the text

How can I extend the AutoComplete feature of a WinForm ComboBox to, for example, find matches of items usin开发者_高级运维g a regular expression or for simplicity to find items that contains the text entered?


The AutoCompleteMode in Windows Forms does not (as of now) support filtering with regular expression or matching from the middle. It supports prefix filtering only.

The API to reset the autocomplete options as you type is IAutoCompleteDropDown::ResetEnumerator. You need to call it in the TextChanged event. On Windows Vista or later you can call IAutoComplete2::SetOptions with ACO_NOPREFIXFILTERING to disable prefix filtering.


For finding the existing list item that best matches what the user has typed, you can set the AutoCompleteMode property on the ComboBox to AutoCompleteMode.Append and the AutoCompleteSource to AutoCompleteSource.ListItems.

If you want to use more complex logic to perform the auto-complete, look at doing something with the TextChanged event. An Example

0

精彩评论

暂无评论...
验证码 换一张
取 消