Following is an example to add an items or remove an items from a list box.Where form will be opened automatically.First drag and drop an objects as required as follows.
Where developer has chosen two buttons, text box, list box and changed name of those buttons also.
Following is the logic code to perform an action that adding an elements and removing an elements.
[c]
Public Class Form1
Private Sub additem_Click(sender As Object, e As EventArgs) Handles additem.Click
lb1.Items.Add(tb1.Text)
lb1.SelectedIndex = lb1.SelectedIndex + 1
End Sub
Private Sub remove_Click(sender As Object, e As EventArgs) Handles removeitem.Click
lb1.Items.Remove(lb1.SelectedItem)
End Sub
End Class[/c]
Output:
Click on start button to compile an application, then the window will be as follows. Where a user can write
an item Names and click on the
Add Item button, then the item will be added to the list box.
Added items will be displayed in the list box as follows.
More items can be added to the list box as follows and when click
Remove Item button the selected item will be deleted.