VB6 Tutorial 42: The Combobox

By | 2018-04-27

In this lesson, I’ll tell you about the ComboBox control in brief.

ComboBox is the combination of a TextBox and a ListBox. The user can type in the text field to select an item or select an item manually from the list. All the properties, events and methods of a ComboBox control are as same as the ListBox control. So the discussion of ListBox control in previous lessons also applies for ComboBox control.

Styles of ComboBox

There are three styles of ComboBox controls– Dropdown Combo, Simple Combo and Dropdown List. You can change/select the style from the Style property of ComboBox.

Example

ComboBox program to select an item from the list

Private Sub cmdSelectBirthYear_Click()
    Print "Your year of birth is" & cboBirthYear.Text
End Sub

Private Sub Form_Load()
    For i = 1980 To 2012
        cboBirthYear.AddItem Str(i)   'Str function returns the 
                             'string representation of a number
        i = Val(i)
    Next i
End Sub

See the attached example combobox.zip to examine the code in your own IDE.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.