Tag Archives: autocomplete

How to add Auto Complete to Textbox or Combobox Controls in Visual Basic 2005/2008, VB.NET 2010, and newer

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 2.83 out of 5)

Note: This is an article which was taken from my vbcodesource.com website and is quite old. So take that into consideration… 🙂

As you will see, adding Auto-Complete support to textbox and combobox controls has NEVER been easier than it is now in Visual Basic.NET 2005. No longer do you HAVE to use the Windows API’s to get the Auto Complete functionality.

I will assume you already have a ‘Windows Application’ based project open. You can go ahead and add a textbox control or combobox control to the form. Select the textbox and goto the properties window. (I will assume you added a textbox, but the process is the same for a combobox also. I will just refer to textbox instead of combobox.)

There are 3x properties that relate to the ‘Auto Complete’ feature. You have “AutoCompleteCustomSource”, “AutoCompleteMode” and “AutoCompleteSource”. AutoCompleteCustomSource is exactly how it sounds. You can have your own text that you want the user to be able to use when they are typing in the control. But, I am not interested in going over that property right now though. There is really nothing more to it than what I already said. 🙂

OK, the “AutoCompleteMode” property is simply how the AutoComplete text responds. Click on the “AutoCompleteMode” property and then open the dropDown list associated with it. You will see 4x ‘modes’ available. “None, “Suggest”, “Append”, and “SuggestAppend”. This property MUST be selected either “Append”, “Suggest”, or “SuggestAppend” for the AutoComplete feature to work. If you select “Suggest” mode, then ‘AutoComplete’ will display a list that matches the text that has been typed thus far that you can scroll through and choose from. If you select “Append” mode, then as you are typing, it will automatically highlight the closest match to the text thus far in the textbox/combobox control, usually in alphabetical order. Plus, while you are typing, you CAN use the ‘Up/Down’ buttons on the keyboard to scroll through the list of text that is similar to the text that was typed in the textbox control. The “SuggestAppend” mode, is of course the combination of the other 2x modes. As you are typing the text, it will highlight the first occurance of matching text while also displaying a list of all the text that matches what has been typed in the control.

The “AutoCompleteSource” property is exactly how it sounds. It is the location on the computer system to get the ‘AutoComplete’ list from. Click on that property and then click on the box to dropdown the enumerator values that are available as the source. Available values, at least on my computer are: “FileSystem”, “HistoryList”, “RecentlyUsedList”, “AllUrl”, “AllSystemSources”, “FileSystemDirectories”, “CustomSource”. Just like the “AutoCompleteMode” property, you MUST select one of these values for you to get ‘AutoComplete’ functionality. Since all of the values are self-explanatory, I will not go over them.

Just to test out the ‘AutoComplete’ feature. With a textbox control, (Or Combobox), click on the “AutoCompleteMode” property and select the “Suggest” mode. Then click on the “AutoCompleteSource” property and then select “AllUrl” as the source. Run the project, start typing in the textbox ‘www’ and you should see a list of url’s you’ve visited that start with ‘www’ popup. You can then click on one of the urls and it will put that url text in the textbox.

And thats ALL there is to it! Enjoy!



How to Autocomplete ComboBoxes like Textboxes using VB and VB.NET

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

I’ve seen this question before and the answer is pretty simple when you get an understanding of the combo control. When you use the handle associated with the Combobox, it is the main portion of the Control that the handle refers to and NOT the edit box which is the important part.

Note: IF your using Classic Visual Basic (5.0 or 6.0) then simply change the int32 and Integer variable types to Long types since the codes here are setup for VB.NET.

To get the handle to this area of the Combobox will require a windows api call. The API Call is: FindWindowEx. This call will get the Handle of the specified control according to the specified Class Name.

    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As  _
        Int32, ByVal hwndChildAfter As Integer, ByVal lpszClass As String, ByVal lpszWindow As String) As Int32

The parameters we are interested in is hWnd and lpszClass. You can set the others to Null. The Handle would be the handle to the main portion of a control. Which is what the ComboBox.Handle.ToInt32 method returns. The class name is the class type you want to get the handle too. Which happens to be “Edit”

        'Will hold the “Edit” handle given by the FindWindowEx API call from the ComboBox.
        Dim cmbHandle As Int32 = FindWindowEx(ComboBox.Handle.ToInt32, 0, "Edit", vbNullString)

And thats all you need to make the combobox Autocomplete capable. Simply specify the cmbHandle integer in the SHAutoComplete ‘handle’ parameter and it will give your combobox the Autocomplete feature!

More Info: If you want the complete source code to autocomplete combobox controls and textbox controls with the actual SHAutoComplete source codes as well, then simply click on this link to view the post.


Revised: 2015