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

Listbox.selectedindex will not return value

I have a listbox that contains numbers that vary from 0 to 99. My problem is when the number in the listbox is 0, listbox1.selectedindex will not return a value. So I cannot use removeat(x) which works for all other numbers. Can anyone give me an idea on how to do it ?

2
Contributors
4
Replies
11 Hours
Discussion Span
1 Year Ago
Last Updated
7
Views
Question
Answered
Gé48
Junior Poster in Training
63 posts since Apr 2010
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 0

Post your code. When I used the following code it worked fine.

    Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        TextBox1.Text = ListBox1.SelectedIndex
    End Sub
Reverend Jim
Carpe per diem
Moderator
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32

Thanks your code helped me getting the indexnumber. I use the indexnumber as an integer named si. I have the code ListBox1.Selected.Item.RemoveAt(si) under a button which will remove any number from the listbox except the number 0 even with the right indexnumber. I don't understand why

Gé48
Junior Poster in Training
63 posts since Apr 2010
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 0

Found this to do the trick, I put the SelectedItem in a TextBox and use Me.ListBox1.Items.Remove(Me.TextBox1.Text)

Gé48
Junior Poster in Training
63 posts since Apr 2010
Reputation Points: 11
Solved Threads: 10
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Reverend Jim

I know it's been solved, but to illustrate further, if you add the following after line 2

If ListBox1.SelectedIndex = 0 Then
    ListBox1.RemoveAt(ListBox1.SelectedIndex)
End If

then clicking on the first element in the list (index=0) will remove it.

Reverend Jim
Carpe per diem
Moderator
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32

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

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0696 seconds using 2.71MB