URGENT HELP NEEDED! Listbox problem
Why doesn't this code work? i want the program to go through each listbox item and give a value to the lstbox() array so that i know which items are selected. If lstbox() = 0 then that item wasnt selected. If lstbox() = 1 then item was selected.
Code:
lstbox(0) = 0
lstbox(1) = 0
lstbox(2) = 0
lstbox(3) = 0
lstbox(4) = 0
lstbox(5) = 0
lstbox(6) = 0
lstbox(7) = 0
lstbox(8) = 0
lstbox(9) = 0
Dim n As Integer = 0
If listbox.SelectedIndex = -1 Then
elephant += 1
Else
Do
If listbox.Items(n) = listbox.SelectedIndex Then 'if client is selected then add a value to array
lstbox(n) = 1
Else
lstbox(n) = 0
End If
n += 1
Loop Until n = 10
End If
Please help!
Re: URGENT HELP NEEDED! Listbox problem
Why don’t you use
VB Code:
Dim indexArray(Me.ListBox1.SelectedIndices.Count - 1) As Integer
Me.ListBox1.SelectedIndices.CopyTo(indexArray, 0)
Re: URGENT HELP NEEDED! Listbox problem
Oh, an urgent problem. Better answer this one quick because all the others are so much less important. :rolleyes:
You get the items that are selected from the ListBox's SelectedItems property. If you just want to know whether a specific item is selected then you use the GetSelected property.
Re: URGENT HELP NEEDED! Listbox problem
I honestly don’t understand the purpose of having an array to keep a record of selected indexes. You can get the info at any time you call the Me.ListBox1.SelectedIndices method.