自动完成功能不适用于文本框 [英] autocomplete functionality not working on a textbox

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

问题描述

我正在尝试在我的桌面应用程序项目中添加自动完成功能..

我有一个用于说明的文本框

但是我在文本框中没有自动完成功能.

我不认识你.


这是代码.我把它放在表单加载事件中

i am trying to add a autocomplete fuctionality in my desktop application project..

i have a textbox for perscription

but i am not getting autocomplete functionility in textbox .

i don''t know y.


here is the code. i put that in form load event

AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();

            OleDbDataReader dReader; 
            OleDbConnection conn = new OleDbConnection(); 
            conn.ConnectionString = connectionString; 
            OleDbCommand cmd = new OleDbCommand(); 
            cmd.Connection = conn; 
           cmd.CommandType = CommandType.Text;
            
           cmd.CommandText = "Select [MedicineName] from [medicines] order by [MedicineName] asc"; 
            conn.Open(); 
            dReader = cmd.ExecuteReader();
            if (dReader.HasRows == true) 
            { 
                while (dReader.Read())   
                namesCollection.Add(dReader["MedicineName"].ToString()); 
            }
            else 
            { 
                MessageBox.Show("Data not found"); 
            } 
            dReader.Close();
           
            txtperscription.AutoCompleteMode = AutoCompleteMode.Suggest;
            
            txtperscription.AutoCompleteSource = AutoCompleteSource.CustomSource;

            txtperscription.AutoCompleteCustomSource = namesCollection;

推荐答案

而不是使用

Instead of using

txtperscription.AutoCompleteSource = namesCollection;



您应该使用



you should use

txtperscription.AutoCompleteCustomSource = namesCollection;



希望对您有帮助



hope this helps


cmd.CommandText = "Select [MedicineName] from [medicines]" + "order by [MedicineName] asc"; 



您没有在[药物]和命令之间放置空格
这是一个非常常见的错误.
为什么在这里使用串联?

更好的尝试:



You didn''t place a whitespace between [medicines] and order by
This is a very common mistake.
Why do you use a concatenation here ?

Better try :

cmd.CommandText = "Select [MedicineName] from [medicines] order by [MedicineName] asc"; 


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

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