问题描述
我通过名称集合的自定义源将 C# TextBox 与 AutoComplete 配合使用,例如John Smith、Mary Jane 等.问题是,如果我输入John",我会在下拉菜单中看到John Smith".但是如果我开始输入Smith",我就不会在下拉菜单中看到John Smith"了.我想改变这一点,我想我必须扩展 TextBox 类并提供我自己的匹配数据的函数.我只是不知道需要覆盖哪个 TextBox 函数.
I'm using C# TextBox with AutoComplete via a Custom Source of a collection of names, e.g. 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 ?
推荐答案
没有直接方法可以做到,因为 AutoCompleteCustomSource
只允许基于输入字符串的前缀匹配.
There is no directly way to do it because AutoCompleteCustomSource
only allows prefix matching based on your input string.
来自 TextBox.AutoCompleteCustomSource
属性
使用 AutoCompleteCustomSource、AutoCompleteMode 和AutoCompleteSource 属性来创建一个自动的 TextBox通过比较输入的 前缀 来完成输入字符串维护源中所有字符串的前缀.
最佳选项似乎覆盖了您的TextBox
的 OnTextChanged 事件.下面的问题有一个很好的例子;
Best option seems to override your OnTextChanged
event of your TextBox
. The question below has a good example about it;
这篇关于C# 文本框自动完成:如何提供自定义 'matching'功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!