VB.Net : Prevent user entering text not in a combobox list

A combobox control in VB.Net can have three possible styles - Simple, Dropdown or DropDownList.

A simple combobox will have the list always visible and user can enter new values that are not in the list.

In DropDownList style, users cannot enter new values. Only values that are already in the list can be selected by clicking the down arrow.

With DropDown style, which is the default style, users can enter new values or select an item from the list by clicking the down arrow.

You can easily change the style from the Properties window, DropDownStyle property or at runtime.

The figure below shows the three different combobox styles

Three different combobox styles

Restricting the text entered on a DropDown style Combobox

On a DropDown style combobox, users can enter any value in the input area of the combobox. If you do not want users to enter values that are not in the list, you could do so with this nice little trick !!

Add the following piece of code to the TextUpdate Event of your combobox