' Project ListBox 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 lstAnimals As System.Windows.Forms.ListBox 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.lstAnimals = New System.Windows.Forms.ListBox() Me.cmdRemove = New System.Windows.Forms.Button() Me.txtValue = New System.Windows.Forms.TextBox() Me.txtIndex = New System.Windows.Forms.TextBox() 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" ' 'lstAnimals ' Me.lstAnimals.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lstAnimals.ItemHeight = 18 Me.lstAnimals.Items.AddRange(New Object() {"Raccoon", "Skunk", "Deer"}) Me.lstAnimals.Location = New System.Drawing.Point(24, 40) Me.lstAnimals.Name = "lstAnimals" Me.lstAnimals.Size = New System.Drawing.Size(216, 148) Me.lstAnimals.TabIndex = 0 ' 'cmdRemove ' Me.cmdRemove.Location = New System.Drawing.Point(144, 200) Me.cmdRemove.Name = "cmdRemove" Me.cmdRemove.Size = New System.Drawing.Size(96, 32) Me.cmdRemove.TabIndex = 2 Me.cmdRemove.Text = "Remove" ' 'txtValue ' Me.txtValue.Location = New System.Drawing.Point(24, 200) Me.txtValue.Name = "txtValue" Me.txtValue.Size = New System.Drawing.Size(104, 26) Me.txtValue.TabIndex = 3 Me.txtValue.Text = "" ' 'txtIndex ' Me.txtIndex.Location = New System.Drawing.Point(24, 240) Me.txtIndex.Name = "txtIndex" Me.txtIndex.Size = New System.Drawing.Size(104, 26) Me.txtIndex.TabIndex = 4 Me.txtIndex.Text = "" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19) Me.ClientSize = New System.Drawing.Size(256, 273) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtIndex, Me.txtValue, Me.cmdRemove, Me.Label1, Me.lstAnimals}) Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Name = "Form1" Me.Text = "ListBox 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 lstAnimals.Items.Add("Oppossum") lstAnimals.Items.Add("Mouse") lstAnimals.Items.Add("Skunk") End Sub Private Sub lstAnimals_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles lstAnimals.Click txtValue.Text = lstAnimals.SelectedItem txtIndex.Text = lstAnimals.SelectedIndex End Sub Private Sub cmdRemove_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdRemove.Click lstAnimals.Items.RemoveAt(lstAnimals.SelectedIndex) End Sub End Class