1,105,254 Community Members

removing items from a list box

Member Avatar
ng5
Light Poster
42 posts since Dec 2011
Reputation Points: 9 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i have a list box and a button. i would like when the button is clicked the selected item in the list box is deleted. any ideas?

Member Avatar
renzlo
Junior Poster
143 posts since Oct 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
-1
 

try this on your button click event:

While myListBox.SelectedItems.Count > 0
	myListBox.Items.Remove(myListBox.SelectedItems(0))
End While
Member Avatar
M.Waqas Aslam
Practically a Posting Shark
837 posts since Aug 2011
Reputation Points: 67 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 4 [?]
Featured
 
0
 

yes you can do it in this way

Try
            ListBox1.Items.Remove(ListBox1.SelectedItem)
        Catch ex As Exception
            MsgBox(Err.Description)
        End Try

Hope this will Solve your prob .

Regards

Member Avatar
kingsonprisonic
Posting Whiz in Training
265 posts since Nov 2009
Reputation Points: 42 [?]
Q&As Helped to Solve: 54 [?]
Skill Endorsements: 0 [?]
 
0
 

Try this....

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.ListBox1.SelectedIndex > -1 Then
            Me.ListBox1.Items.RemoveAt(Me.ListBox1.SelectedIndex)
        End If
    End Sub
Member Avatar
Jx_Man
Senior Poster
3,543 posts since Nov 2007
Reputation Points: 987 [?]
Q&As Helped to Solve: 542 [?]
Skill Endorsements: 74 [?]
Featured
 
0
 

See this following code :

For i As Integer = 0 To ListBox1.SelectedIndices.Count - 1
   ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
Next

Or you use this too :

Do While (ListBox1.SelectedItems.Count > 0)
   ListBox1.Items.Remove(ListBox1.SelectedItem)
Loop
Member Avatar
ng5
Light Poster
42 posts since Dec 2011
Reputation Points: 9 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks for the help :)

Question Answered as of 2 Years Ago by M.Waqas Aslam, renzlo, Jx_Man and 1 other
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: