Remove an Item From ListBox - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

Removing selected Item

The following code is used to remove the selected item from the listbox:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
        ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub



Removing all items

The following code is used to remove all items from listbox:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
        ListBox1.Items.Clear()
End Sub


Removing specific item:

The following code is used to remove an item that user enter itís index in a textbox:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
        ListBox1.SelectedIndex = TextBox1.Text
        ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub


Share This

Home | About | Contact | Privacy Policy

Copyright © visual-basic-tutorials.com 2017 - All Rights Reserved.