The ComboBox control is very useful in a variety of situations, but many programmers aren't making the most of it because they don't understand how its Style property works.
Doing it with style
By default, a ComboBox control's Style property is set to vbComboDropDown (value = 0). This is the default style because it results in a ComboBox that works the way programmers usually want it to work. The control displays as a single-line text box with a down arrow at the right side. The user can type directly into the control or, by clicking the arrow, can select from the predefined items that have been loaded into the control. This style saves screen real estate because the list of items is hidden until the user clicks the arrow.
Setting the Style property to vbComboSimple (value = 1) results in a control that looks like a text box above a list box. As with the default style, the user can type in the text box or select from the list. The advantage is that the list always makes the available choices visible to the user. The disadvantage is that the control takes up more room on the screen.
The third ComboBox style is vbComboDrop-DownList (value = 2). When you select this style, theComboBox displays the same way as with the default style (i.e., a single-line text box with a down arrow at the right side). The variation is in the behavior; the user cannot type data into the control—he or she must select from the list. In other words, a ComboBox with the Style property set to vbComboDrop-DownList looks like a ComboBox but acts like a ListBox.
By understanding how a ComboBox control's Style property affects its behavior and appearance, you can select the best setting for your application.
Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!