[2005] Iterate Through MultiSelect ListBox
I have a multiselect Listbox on a Form. I need to iterate through this listbox and do something with all of the items that have been selected. Nothing I've tried has worked. Here is my lastest attempt.
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim item As Object
For i As Integer = ListBox1.Items.Count - 1 To 0 Step -1
If ListBox1.SelectedItems(i) = True Then
'do something with them
End If
Next
End Sub
So, how do I go through the entire listbox and do my thing what all of the items that have been selected?
Re: [2005] Iterate Through MultiSelect ListBox
Why would you want to use the .SelectedItems collection and try to loop through all the items? You only need to loop through the selecteditems collection. ;)