Click here to Skip to main content
15,898,827 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a search textbox of Google, when I dynamically change the search suggestions in the textbox as autocomplete it shows only for a while and disappears, maybe it's about the control losing focus but that also didn't help! why?

What I have tried:

<pre>SearchSuggestionsAPI s = new SearchSuggestionsAPI();
AutoCompleteStringCollection a = new AutoCompleteStringCollection();

   private async void textBoxMain_TextChanged(object sender, EventArgs e)
        {
            textBoxMain.Focus();
            textBoxMain.Select();

            a = new AutoCompleteStringCollection();


            if (string.IsNullOrWhiteSpace(textBoxMain.Text))
            {
                textBoxMain.AutoCompleteCustomSource = a;
                return;
            }

            

            foreach ( GoogleSuggestion g in (IEnumerable<GoogleSuggestion>) (await s.GetSearchSuggestions(textBoxMain.Text)))
            {
                if (!string.IsNullOrWhiteSpace(g.Phrase))
                {
                    a.Add(g.Phrase);
                }
            }

            

            textBoxMain.AutoCompleteCustomSource = a;
        }


bool mouseOver = false;

        private void textBoxMain_MouseEnter(object sender, EventArgs e)
        {
            mouseOver = true;
        }

        private void textBoxMain_MouseLeave(object sender, EventArgs e)
        {
            mouseOver = false;
        }

        private void textBoxMain_Leave(object sender, EventArgs e)
        {
            if(mouseOver)
            {
                textBoxMain.Focus();
                textBoxMain.Select();
                textBoxMain_TextChanged(null, null);
            }
        }
Posted

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