1

I'm trying out Visual Studio's auto complete for textbox and so far it's doing good but I currently am having problems on how could I improve the suggestions since as for now, it only shows the words starting with the letter I type sorta if I typed a, it would show Apple, Ant, Axe. I kinda wanted it to also suggest words that doesn't start with a but still has that a letter inside them, words like Zebra, Camel, Boat, Bear.

Here's my current code:

void AutoCompleteText()
    {
        Search_text.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
        Search_text.AutoCompleteSource = AutoCompleteSource.CustomSource;
        AutoCompleteStringCollection coll = new AutoCompleteStringCollection();

        SqlCommand cmdDataBase = new SqlCommand("SELECT * FROM item", sc);
        SqlDataReader textboxReader;

        try
        {
            sc.Open();
            textboxReader = cmdDataBase.ExecuteReader();

            while(textboxReader.Read())
            {
                string sName = textboxReader["item_name"].ToString();
                coll.Add(sName);
            }

            sc.Close();
        }

        catch(Exception ext)
        {
            richTextBox1.Text = ext.ToString();
        }

        Search_text.AutoCompleteCustomSource = coll;
    }

(Sorry for the incredibly long title, I just wanted to explain the entire dilemma on the title, the VS is for Visual Studio, I made it to VS as I will actually exceeded the 150 character limit if I make it Visual Studio)

  • Possible duplicate of [AutoComplete TextBox with Features of Like Clause example %hello% C# Windows](http://stackoverflow.com/questions/1524166/autocomplete-textbox-with-features-of-like-clause-example-hello-c-sharp-window) – fujiFX Oct 16 '15 at 04:04
  • Please refer the [MSDN link](http://msdn.microsoft.com/en-us/library/bb776292%28VS.85%29.aspx) as suggested in the related question for an alternate way of achieving your requirement. – fujiFX Oct 16 '15 at 04:06
  • Unfortunately, this is no default property or feature in `TextBox` control. See here how you can create your own `AutoComplete` using a `ListBox`: http://stackoverflow.com/a/13892238/2679160 – roemel Oct 16 '15 at 06:07
  • 1
    Just a heads up on my current progress. I actually just decided to stop working on Windows Forms as I realized it's just too limited for me as fixing this could pontentially help me for now, but I might not be so lucky finding a solution to other problems I might have on the future so I now started using WPF and I've got to say, it was one of the best decisions I've made. What's even great about this is that since I have an account in Digital Tutors, I could use it to login to Pluralsight to access tons of trainings for WPF. I could make up for lost time trying to fix little things in winform. – Flex Luthor Oct 16 '15 at 15:46

0 Answers0