自动完成文本框无效c# [英] Auto complete textbox is not working c#

查看:77
本文介绍了自动完成文本框无效c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用下面的代码。它在组合框中运行良好。但在文本框中它没有填充任何建议。我在文本框属性中是否有误?



请帮助我。

Hi

I am used the below code. It is working fine the combobox. but in the text box it does not populating any suggestion. am i misssing anything in the textbox properties ?

Please help me .

AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
            SqlDataReader dReader;
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=" ";Initial Catalog=" ";User ID=" ";Password=" "";
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select distinct UserName from Users order by UserName asc";
            conn.Open();
            dReader = cmd.ExecuteReader();
            if (dReader.HasRows == true)
            {
                while (dReader.Read())
                {
                    namesCollection.Add(dReader["UserName"].ToString());
                }

            }
            else
            {
                MessageBox.Show("Data not found");
            }
            dReader.Close();

            comboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
            comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            comboBox1.AutoCompleteCustomSource = namesCollection;

            textbox1.AutoCompleteMode = AutoCompleteMode.Suggest;
            textbox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
            textbox1.AutoCompleteCustomSource = namesCollection;

推荐答案

添加以下行

Add the following line
textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;



这将填充文本框并显示建议列表



见下面OP的评论。即使在上面应用后文本框也不起作用。

他删除了multiline = true属性并且它有效。


This will populate the text box and also show the list of suggestions

See comments from OP below. Even after applying above the textbox did not work.
He removed multiline=true property and it worked.


这篇关于自动完成文本框无效c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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