A ComboBox control combines the features of a text box and a list box. This control enables the user to select an item either by typing text into the combo box, or by selecting it from the list.
Combo boxes present a list of choices to the user. If the number of items exceeds what can be displayed in the combo box, scroll bars will automatically appear on the control. The user can then scroll up and down or left to right through the list.
There are three combo box styles. Each style can be set at either design or run time and uses the following values to set the style of the combo box.
Style | Value |
---|---|
Drop-down Combo Box | 0 |
Simple Combo Box | 1 |
Drop-down List Box | 2 |
ComboBox
The ComboBox control has the following properties, methods, and events.
Generally, a combo box is appropriate when there is a list of suggested choices, and a list box is appropriate when you want to limit input to what is on the list. A combo box contains an edit field, so choices not on the list can be typed in this field.
In addition, combo boxes save space on a form. Because the full list is not displayed until the user clicks the down arrow (except for Style 1, which is always dropped down), a combo box can easily fit in a small space where a list box would not fit.
To add or delete items in a ComboBox control, use the AddItem or RemoveItem method. Set the List, ListCount, and ListIndex properties to enable a user to access items in the ComboBox. Alternatively, you can add items to the list by using the List property at design time.
A Scroll event occurs in a ComboBox control only when the contents of the dropdown portion of the ComboBox are scrolled, not each time the contents of the ComboBox change. For example, if the dropdown portion of a combo box contains five items and the top item is highlighted, a Scroll event will not occur until you press the down arrow six times (or the PgDn key once). After that, a Scroll event occurs for each press of the down arrow key. However, if you then press the up arrow key, a Scroll event will not occur until you press the up arrow key six times (or the PgUp key once). After that, each up arrow key press will result in a Scroll event.