本文介绍了自动完成文本框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个文本框控件,用于在使用 C# 2008 和 LINQ 的 Windows 应用程序中建议和附加来自数据库的值.
I want to have a textbox control that suggests and append values from a database in a Windows application with C# 2008 and LINQ.
我用组合框来做,但我不能用文本框来做.
I do it with a combobox but I can't do it with a 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; } } }更多推荐
自动完成文本框控件
发布评论