' Project ComboBox ' Add items to the combo box at design time and run time. ' Display and remove items. Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents cboAnimals As System.Windows.Forms.ComboBox Friend WithEvents cmdRemove As System.Windows.Forms.Button Friend WithEvents txtIndex As System.Windows.Forms.TextBox Friend WithEvents txtValue As System.Windows.Forms.TextBox 'Required by the Windows Form Designer Private components As System.ComponentModel.Container 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.cmdRemove = New System.Windows.Forms.Button Me.txtValue = New System.Windows.Forms.TextBox Me.txtIndex = New System.Windows.Forms.TextBox Me.cboAnimals = New System.Windows.Forms.ComboBox Me.SuspendLayout() ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(24, 8) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(192, 16) Me.Label1.TabIndex = 1 Me.Label1.Text = "North American Animals" ' 'cmdRemove ' Me.cmdRemove.Location = New System.Drawing.Point(24, 168) Me.cmdRemove.Name = "cmdRemove" Me.cmdRemove.Size = New System.Drawing.Size(184, 32) Me.cmdRemove.TabIndex = 2 Me.cmdRemove.Text = "Remove" ' 'txtValue ' Me.txtValue.Location = New System.Drawing.Point(24, 88) Me.txtValue.Name = "txtValue" Me.txtValue.Size = New System.Drawing.Size(184, 26) Me.txtValue.TabIndex = 3 Me.txtValue.Text = "" ' 'txtIndex ' Me.txtIndex.Location = New System.Drawing.Point(24, 128) Me.txtIndex.Name = "txtIndex" Me.txtIndex.Size = New System.Drawing.Size(184, 26) Me.txtIndex.TabIndex = 4 Me.txtIndex.Text = "" ' 'cboAnimals ' Me.cboAnimals.Items.AddRange(New Object() {"Raccoon", "Mouse", "Deer"}) Me.cboAnimals.Location = New System.Drawing.Point(24, 40) Me.cboAnimals.Name = "cboAnimals" Me.cboAnimals.Size = New System.Drawing.Size(184, 28) Me.cboAnimals.TabIndex = 5 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19) Me.ClientSize = New System.Drawing.Size(240, 222) Me.Controls.Add(Me.cboAnimals) Me.Controls.Add(Me.txtIndex) Me.Controls.Add(Me.txtValue) Me.Controls.Add(Me.cmdRemove) Me.Controls.Add(Me.Label1) Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Name = "Form1" Me.Text = "ComboBox Example" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load cboAnimals.Items.Add("Oppossum") cboAnimals.Items.Add("Mouse") cboAnimals.Items.Add("Skunk") End Sub Private Sub cboAnimals_SelectedIndexChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cboAnimals.SelectedIndexChanged txtValue.Text = cboAnimals.SelectedItem txtIndex.Text = cboAnimals.SelectedIndex End Sub Private Sub cmdRemove_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdRemove.Click Dim i As Integer i = cboAnimals.SelectedIndex cboAnimals.Items.RemoveAt(i) txtValue.Clear() txtIndex.Clear() cboAnimals.Text = "" End Sub End Class