Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# C#4.0 .NET4 WinForm
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...
 
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 4-Jul-13 6:14am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes, I rectify this Issue...Use Form_Load Instead of Text_Changed Event..BCoz it should assign only once.
 
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)
{ }
 
}
  Permalink  
Comments
Azeem. at 20-Feb-14 6:16am
   
But what is solution if number of records are in millions ?????
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use Form_Load Instead of Text_Changed Event..BCoz it should assign only once.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 4 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100