自动完成文本框控件

编程入门 行业动态 更新时间:2024-10-26 10:38:38
本文介绍了自动完成文本框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想要一个文本框控件,用于在使用 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; } } }

更多推荐

自动完成文本框控件

本文发布于:2023-11-11 23:48:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579887.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   文本框   自动完成

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!