We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,318 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

removing items from a list box

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?

5
Contributors
5
Replies
10 Hours
Discussion Span
1 Year Ago
Last Updated
6
Views
Question
Answered
ng5
Light Poster
42 posts since Dec 2011
Reputation Points: 19
Solved Threads: 0
Skill Endorsements: 0

try this on your button click event:

While myListBox.SelectedItems.Count > 0
	myListBox.Items.Remove(myListBox.SelectedItems(0))
End While
renzlo
Junior Poster
129 posts since Oct 2011
Reputation Points: 14
Solved Threads: 6
Skill Endorsements: 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

M.Waqas Aslam
Master Poster
761 posts since Aug 2011
Reputation Points: 58
Solved Threads: 126
Skill Endorsements: 2

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
kingsonprisonic
Posting Whiz in Training
268 posts since Nov 2009
Reputation Points: 61
Solved Threads: 54
Skill Endorsements: 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
Jx_Man
Senior Poster
3,553 posts since Nov 2007
Reputation Points: 1,500
Solved Threads: 531
Skill Endorsements: 65

thanks for the help :)

ng5
Light Poster
42 posts since Dec 2011
Reputation Points: 19
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Jx_Man, kingsonprisonic, M.Waqas Aslam and 1 other

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0950 seconds using 2.72MB