如何使用Windows应用程序中值的最后一位数字在文本框中获取自动建议 [英] How do I get autosuggestions in textbox using last digits of a value in windows applications

查看:66
本文介绍了如何使用Windows应用程序中值的最后一位数字在文本框中获取自动建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理Windows应用程序。我有一个自动提示的文本框。我在autosuggestioncollection中添加了一些值。如果我键入值的第一个字母,则表示添加的值,但如果我键入值的最后几个字母。即使我输入值的最后几个字母,我也需要它来显示建议。



我尝试了什么:



I am working on windows applications. I have a text box with autosuggestion on. i have added few values in autosuggestioncollection. if i type first letter of the value,it is suggesting the added values but if i type last few letters of the value. I need it to show the suggestions even if i enter the last few letters of the value.

What I have tried:

AutoCompleteStringCollection mycollection = new    AutoCompleteStringCollection();
mycollection.Add("TEST12345");
mycollection.Add("TEST13456");
mycollection.Add("TEST22222");
mycollection.Add("TEST99999");
textBox1.AutoCompleteCustomSource = mycollection;

推荐答案

嗯......这是AutoCompleteCustomSource [ ^ ],因为它通过将输入的前缀与维护源中的所有字符串的前缀进行比较 ,自动完成输入字符串。



如果你想要更改它,你必须创建 textBox1_Click 事件,然后你可以实现一个方法,将输入的字符串与自定义源字符串进行比较。例如:

Well... This is normal behaviour of control with AutoCompleteCustomSource[^], because it automatically completes input strings by comparing the prefix being entered to the prefixes of all strings in a maintained source.

If you would like to change it, you have to create textBox1_Click event and there you can implement a method which compare entered string with a string of custom source. For example:
TextBox txt = (TextBox)sender;
if(txt.Text.Length<2) return;
string s = txt.Text;
s = txt.AutoCompleteCustomSource.OfType<string>.FirstOrDefault(x=> x.Contains(s));
if(s != string.Empty) txt.Text = s;





TextBox 的属性设置如下所示时,它按预期工作:



It works as expected, when below properties of TextBox are set as shown:

AutoCompleteMode = SuggestAppend;
AutoCompleteSource = CustomSource;


这篇关于如何使用Windows应用程序中值的最后一位数字在文本框中获取自动建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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