Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > ComboBox/TextBox search functionallity
 

ComboBox/TextBox search functionallity

Hi everyone,
I've been trying to develop a textbox(or combobox) that mimics the functionality of a address bar. For example, in Mozilla FireFox or in Internet Explorer when you type a letter into the address bar it shows a listbox filled with suggestions based on the currently written word in the address bar, actually it shows every address known that contains inside it(not only beginning with) the typed letter.
I know that the textbox/combobox have the autocomplete function, but it is based only on the first letter of the typed word.
What I actually want to do is a combobox that updates it's Items collection based upon the word written inside it.

How can I do that?
SlbtzenBV  Friday, April 24, 2009 4:25 PM
If you are using VS 2008, you can use Lambda expressions to do this.

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            // Filter the ListBox to those values that container the entered text
            List<string> myList = new List<string> { "First item in list", "Second item in list", "Third item in list" };

            var filteredList = myList.Where(s => s.Contains(textBox1.Text));

            listBox1.DataSource = filteredList.ToList();

        }
This is a case sensitive compare. You can use .ToLower or .ToUpper if you want a case insensitive compare.

Hope this helps.
www.insteptech.com
DeborahK  Friday, April 24, 2009 4:40 PM
If you are using VS 2008, you can use Lambda expressions to do this.

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            // Filter the ListBox to those values that container the entered text
            List<string> myList = new List<string> { "First item in list", "Second item in list", "Third item in list" };

            var filteredList = myList.Where(s => s.Contains(textBox1.Text));

            listBox1.DataSource = filteredList.ToList();

        }
This is a case sensitive compare. You can use .ToLower or .ToUpper if you want a case insensitive compare.

Hope this helps.
www.insteptech.com
DeborahK  Friday, April 24, 2009 4:40 PM
Thank you DeborahK,
What i'm actually trying to figure out is how to put the textbox and the listbox together form a control design point of view. So basicaly i would like to create a new CustomControl, that put those 2 together. I've tried but didn't come out very succesfull.
SlbtzenBV  Friday, April 24, 2009 4:57 PM
If you just want a textbox and list box that always appear, you can create a composite control and add the TextBox and ListBox to it. You would then need to expose all of the properties/events that you would want.

It will be quite a bit of work (owner draw I would imagine) to get this to look reallynice ...

If the question is not on the search itself but rather on getting it to draw nicely, you might want to repost with a different question title to get the right people reading your question.

Hope this helps.
www.insteptech.com
DeborahK  Friday, April 24, 2009 6:29 PM
Yes, that owner drawing issue is what i'm actually looking to solve. I'll try to repost this issue.
Thank you very much for your help.
SlbtzenBV  Friday, April 24, 2009 8:03 PM

You can use google to search for other answers

Custom Search

More Threads

• Working with uniqueidentifier
• datagridview basic understanding
• BindingList override SetItem
• DataGridView BindingSource Change Position
• Need help with filtering or maybe binding
• Auto Update Database on Editing DataGridView
• DataGridViewCell Painting Problem
• does bindingsource.filter doesn't provide multiple filter operations
• datagridview calender column
• Problem selecting rows in datagrid .net 1.1 after using FindRows