' Project: Combo and List Boxes ' Programmer: Andy McCone ' Date: Winter 2008 'Description: This example shows you how you can ' Add items ' Remove items ' Reference items ' Count items Public Class mainForm Private Sub addButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addButton.Click ' to add text entry into fruitComboBox item Collection fruitComboBox.Items.Add(fruitComboBox.Text) End Sub Private Sub remove1Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles remove1Button.Click ' To allow user to delete entry from list fruitComboBox.Items.Remove(fruitComboBox.Text) End Sub Private Sub remove2Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles remove2Button.Click ' To allow user to delete entry from list fruitComboBox.Items.RemoveAt(fruitComboBox.SelectedIndex) End Sub Private Sub countButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles countButton.Click Dim countInteger As Integer 'Capture the number of items in the Combobox and ' display multiple lines in a messagebox countInteger = fruitComboBox.Items.Count MessageBox.Show("We have " & countInteger & " types of fruit" & ControlChars.NewLine & "Thank you so much for asking") End Sub Private Sub selectButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles selectButton.Click 'Choose to highlight an item from the Listbox suppliesListBox.SelectedIndex = 3 'Capture the highlighted item in the Listbox and display elsewhere displayMiddleLabel.Text = suppliesListBox.Text End Sub End Class