Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Combo Boxes

Combo boxes work much like list boxes except that the user can add items to a combo box at runtime, whereas the user can only scroll and select items from a list box at runtime. Visual Basic supports three kinds of combo boxes, and the kind you select depends on the combo box you want to display on the form and on the ability you want the user to have. All the list box methods that you learned about in the previous section apply to combo boxes.

Here are the three kinds of combo boxes:

Figure 10.5 shows the three kinds of combo boxes. Each combo box contains the names of people that you saw in Figure 10.4. The first combo box, the drop-down combo box, is normally closed; when the user clicks its down arrow, the combo box opens. The third combo box, the drop-down list box, is left unopened. If the user opens the drop-down list box, the user will see a list of people's names but will not be able to add to the names because no data entry is possible in drop-down list boxes.

10fig05.gif

Figure 10.5 Use Style to change the combo box appearance.

Table 10.3 describes some of the combo box properties.

Table 10.3. The fundamental combo box properties.

Property Description
BackColor The combo box's background color.
ForeColor The combo box's foreground text color.
Height The height, in twips, of the closed combo box.
IntegralHeight Determines whether the combo box can display partial items, such as the upper half of an item that falls toward the bottom of the combo box.
List A drop-down property list box where you can enter values into the combo box at design time. You can enter only one at a time, and most programmers prefer to initialize the combo box at runtime.
Sorted Determines whether the combo box values are automatically sorted. If False (the default value), the values appear in the same order in which the program added the items to the combo box.
Style Determines the type of combo box your application needs. If 0-DropDown Combo, the combo box is a drop-down combo box. If 1-Simple Combo, the combo box turns into a simple combo box that remains open to the height you used at design time. If 2-DropDown List, the combo box turns into a drop-down list box that remains closed until the user is ready to see more of the list.

Share ThisShare This

Informit Network