The document discusses various ways to manipulate items in a ListBox control in Visual Basic. It describes code for:
1) Removing the text from TextBox1 from the ListBox1 items using a button click event
2) Clearing all items from ListBox1 using a separate button
3) Removing the currently selected ListBox1 item when the selection changes
4) Copying the selected ListBox1 item text to TextBox2 on regular click
5) Removing the selected ListBox1 item on double click.
3. Dr. Girija Narasimhan 3
'Remove it will remove only textbox1. Text information from listbox1 not listbox1 items
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ListBox1.Items.Remove(TextBox1.Text)
End Sub
'remove_all it will remove all the listbox1 items from listbox1
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
ListBox1.Items.Clear()
End Sub
' If you place the cursor in the listbox1 particular item- it will remove only that item
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles
ListBox1.SelectedIndexChanged
'ListBox1.Items.Remove(ListBox1.Text)
End Sub
4. Dr. Girija Narasimhan 4
'which item in the listbox if you click that will paste in the textbox2
Private Sub listbox1_click(sender As Object, e As EventArgs) Handles ListBox1.Click
TextBox1.Text = ListBox1.SelectedItem
End Sub
'if you doubleclick the selected item in the listbox it will remove
Private Sub listbox1_doubleclick(sender As Object, e As EventArgs) Handles
ListBox1.DoubleClick
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
End Class