Private sub loopthoughlistbox
Dim x as interger = 0
‘set to count how many items I have in the listbox
x = listbox2.Items.Count
Dim index, theindex As Integer
index = 0
‘this will process in order since yoru starting with x as highest
Do Until x < 1
'remember the count is not zero based 3 items = count of 3 not 2
As the third item selected is in table position 2
Dim c As String
Dim d As String
index = x – 1
‘this fake it out and it thinks this item is the selected one
listbox2.SetSelected(index, True)
b = CType(listbox2.SelectedItem, clsCategoryListItem).itemID
‘do sub to load whatever
‘Set x down by one
x = x - 1
Loop
End sub
Put in order entered
‘replace with this if you want to do it in ordered entered
Dim x as interger = 1
Dim index, theindex As Integer
Do Until x > listbox2.Items.Count
'remember the count is not zero based 3 items = count of 3 not 2
As the third item selected is in table position 2
Dim c As String
Dim d As String
index = x – 1
‘this fakes it out and it thinks this item is the selected one
listbox2.SetSelected(index, True)
b = CType(listbox2.SelectedItem, clsCategoryListItem).itemID
‘do sub to load whatever
‘Set x up by 1
x = x + 1
Loop
Done forget you will go though selectedIndexChanged sub if you have one each time you change index above
Private Sub listbox2selected(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listbox2.SelectedIndexChanged
‘ you always need to check if somehting is in the listbox
If Not IsNothing(listbox2.SelectedItem) Then
‘Do whatever
End If
End Sub
There are plenty of examples showing you how add to a listbox.
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)