Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

C#
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;
Posted
Updated 7-Oct-11 2:29am
v4

Instead of using

C#
txtperscription.AutoCompleteSource = namesCollection;


you should use

C#
txtperscription.AutoCompleteCustomSource = namesCollection;


hope this helps
 
Share this answer
 
v2
Comments
codegeekalpha 7-Oct-11 4:36am    
thx but now i am getting no error. but autocomplete functionality is not working...
Wayne Gaylard 7-Oct-11 4:47am    
You should make sure you are getting results from your query, as there is no other errors in the code.
codegeekalpha 7-Oct-11 5:19am    
query is right.... and their is also data in the table field MedicineName. but my application is not fething the data..

i wrote a query for the table medicines having attributes MedicineName and DateAdded. iss that query is right??
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"; 
 
Share this answer
 
v2
Comments
codegeekalpha 7-Oct-11 8:29am    
its still not working :(
codegeekalpha 7-Oct-11 8:30am    
no syntax error
but not working..
codegeekalpha 7-Oct-11 8:39am    
thx i figure out the problem.. i set textfield in multiline field..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900