C#文本框自动完成功能:如何提供自定义的“匹配"功能? [英] C# Textbox Autocomplete: How to provide custom 'matching' function?

查看:191
本文介绍了C#文本框自动完成功能:如何提供自定义的“匹配"功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过名称集合的自定义来源"将C#文本框与自动完成"功能配合使用,例如问题是,如果我键入"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 通过将输入的前缀与 维护的源中所有字符串的前缀.

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.

最佳选择似乎会覆盖您的 OnTextChanged TextBox的事件.下面的问题有一个很好的例子;

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

这篇关于C#文本框自动完成功能:如何提供自定义的“匹配"功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆