自动完成TextBox控件 [英] AutoComplete TextBox Control
本文介绍了自动完成TextBox控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个文本框控件,它给予建议,并从Windows应用程序丝毫C#2008和LINQ数据库追加。
I want to have a textbox control that it give suggest and append from a database in win application whit C# 2008 and LINQ .
我这样做,丝毫组合框,但我不能这样做丝毫的文本框。
I do it whit Combobox but I can't do it whit textbox .
我该怎么办呢?
推荐答案
这可能不是做事情的最好方法,但应该工作:
This might not be the best way to do things, but should work:
this.textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox t = sender as TextBox;
if (t != null)
{
//say you want to do a search when user types 3 or more chars
if (t.Text.Length >= 3)
{
//SuggestStrings will have the logic to return array of strings either from cache/db
string[] arr = SuggestStrings(t.Text);
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
collection.AddRange(arr);
this.textBox1.AutoCompleteCustomSource = collection;
}
}
}
这篇关于自动完成TextBox控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文