Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In C# Winforms, I have a textbox with AutoCompleteMode. When the user types some letters the suggestion list is shown Correctly. If an item in list is selected using (Keyboard)UP and Down key it could not Select an item. If i Select mean, it will get the first item in list..

How can i rectify this...Please Suggest..

Here My Code...

C#
private void txt_Name_TextChanged(object sender, EventArgs e)
        {
            try
            {
                SqlDataReader datareader = qu.GetValue("English_Short");
                AutoCompleteStringCollection local = new AutoCompleteStringCollection();
                if (datareader.HasRows == true)
                {
                    while (datareader.Read())
                        local.Add(datareader["English_Short"].ToString());
                }
                txt_Name.AutoCompleteMode = AutoCompleteMode.Suggest;
                txt_Name.AutoCompleteSource = AutoCompleteSource.CustomSource;
                txt_Name.AutoCompleteCustomSource = local;
            }
            catch (Exception)
            { }
        }
Posted

Yes, I rectify this Issue...Use Form_Load Instead of Text_Changed Event..BCoz it should assign only once.

C#
private void Form_Load(object sender, EventArgs e)
        {
            try
            {
                SqlDataReader datareader = qu.GetValue("ITEM_CODE");
                using (DataTable dt = new DataTable())
                {
                    dt.Load(datareader);
                    AutoCompleteStringCollection local = new AutoCompleteStringCollection();
                    if (dt.Rows.Count >= 0)
                    {
                        for (int count = 0; count < dt.Rows.Count; count++)
                        {
                            local.Add(dt.Rows[count]["ITEM_CODE"].ToString());
                        }
                    }
                    txt_Code.AutoCompleteMode = AutoCompleteMode.Suggest;
                    txt_Code.AutoCompleteSource = AutoCompleteSource.CustomSource;
                    txt_Code.AutoCompleteCustomSource = local;
                }
            }

catch (Exception)
{ }

}
 
Share this answer
 
Comments
DoingWork 20-Feb-14 6:16am    
But what is solution if number of records are in millions ?????
Use Form_Load Instead of Text_Changed Event..BCoz it should assign only once.
 
Share this answer
 

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