Click here to Skip to main content
15,921,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 .
C#
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;
Posted
Updated 13-Mar-13 1:19am
v3
Comments
shrikantshimgekar 31-May-18 2:13am    
Sorry This changes does not work for my problem ..still i am not getting the drop down list

1 solution

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

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

[Edit] See comments from OP below. Even after applying above the textbox did not work.
He removed multiline=true property and it worked.
 
Share this answer
 
v2
Comments
Ayyappan Ravi 12-Mar-13 9:23am    
No its not working.....
CHill60 12-Mar-13 9:39am    
I actually typed most of your code in (apart from reading from the database) and it all worked as I expected it to. So what exactly is happening with your text box?
Ayyappan Ravi 12-Mar-13 10:01am    
The taxtbox is not populating any suggestions. but the same thing working fine in the comboBox.
CHill60 12-Mar-13 11:31am    
Sorry - your code works fine for me. The comboBox doesn't populate with just the code above as there are no items in it, but it works if I add items to the comboBox when setting up namesCollection. But the text box is working fine. I just dumped a textBox onto a form and didn't make any changes other than those in the code if that helps
Ayyappan Ravi 12-Mar-13 11:52am    
now its working fine with both textbox and combobox...


Thanks..

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



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