Visual Basic Concepts
Using List Boxes and Combo Boxes
List boxes and combo boxes present a list of choices to the user. By default, the choices are displayed vertically in a single column, although you can set up multiple columns as well. If the number of items exceeds what can be displayed in the combo box or list box, scroll bars automatically appear on the control. The user can then scroll up and down or left to right through the list. Figure 3.14 shows a single-column list box.
Figure 3.14 Single-column list box
A combo box control combines the features of a text box and a list box. This control allows the user to select either by typing text into the combo box or by selecting an item from its list. Figure 3.15 shows a combo box.
Figure 3.15 Combo box
In contrast to some other controls that contain a single value; for example the label's Caption property or the text box's Text property, list boxes and combo boxes contain multiple values or a collection of values. They have built-in methods for adding, removing and retrieving values from their collections at run time. To add several items to a list box named List1, the code would look like this:
List1.AddItem "Paris" List1.AddItem "New York" List1.AddItem "San Francisco"
List boxes and combo boxes are an effective way to present a large number of choices to the user in a limited amount of space.
*For More Information* For additional information on the list box and combo box controls, see "Using Visual Basic's Standard Controls."