Controls: ComboBox

  • Combines TextBox features with a short drop down list.  
  • ComboBox has three different styles:
    • ComboBoxStyle.DropDown the default style that allow the user to type data directly into the ComboBox as well as select items from the drop down list.  
    • ComboBoxStyle.Simple appears as a TextBox with no drop down list.  
    • ComboBoxStyle.DropDownList requires the user to select items from the drop down list.  Does not allow the user to enter data directly.

  • Some ComboBox Properties:
    • Items.Count number of drop-down list items.
    • SelectedIndex The index of the selected item.  If no item is selected, SelectedIndex is -1.
    • The index of the last item added to the ComboBox.  
      • Dim newIndex As Integer
        newIndex = List1.Items.Add("Hello")

  • To add item to a ComboBox
    • Items.Insert or
    • Items.Add  
  • To remove item from a ComboBox:
    • Items.Remove  
  • To clear all items in a ComboBox:
    • Items.Clear  
  • To display an item in the ComboBox:
    • cmbCombo.Text = txtInput.Text  
  • To retrieve an item from a ComboBox:
    • item = cmbCombo.Text

To reset a combo box so that entries are no longer highlighted, first set the list index to 0 and then reset it to -1.

cmbCombo.SelectedIndex = 0
SelectedIndex = -1

See also List Box Clues for help populating a combo box, etc.

ComboBox Control Changes in Visual Basic .NET