How can I check if one item is selected in a list box ???
[Edited by pro2 on 10-06-2000 at 05:26 PM]
Printable View
How can I check if one item is selected in a list box ???
[Edited by pro2 on 10-06-2000 at 05:26 PM]
If list1.text = "yourtext" then Msgbox "Selected"
If list1.listindex = 1 then Msgbox "ListIndex " list1index selected
To check a specific item
To see if any item is selectedCode:If List1.Selected(5) = True Then
'Item 5 is selected
End If
Code:For i = 0 To List1.ListCount
If List1.Selected(i) Then 'There is an item selected
Next i
is it
For i = 0 To List1.ListCount
If List1.Selected(i) Then 'There is an item selected
Next i
or
For i = 0 To List1.ListCount -1
If List1.Selected(i) Then 'There is an item selected
Next i
??
cause the List count start to 1 and the Index start to 0 ..
The listindex is zero based
so from 0 to list1.listcount -1
Ok thank'x a lot..
its workin..
but you forgot the
= True
in the second exemple Megatron ..
For i = 0 To List1.ListCount
If List1.Selected(i) Then 'There is an item selected
Next i
You don't need the True for it to work
However he did forget the list1.lsitcount -1
and the end if
But I'm sure you figured that out.
:D
Code:For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
MsgBox "selected " & List1.ListIndex
'There is an item selected
End If
Next i
Actually he didn't leave the End If out... it is not necessary if the Then isQuote:
Originally posted by HeSaidJoe
However he did forget the list1.lsitcount -1
and the end if
But I'm sure you figured that out.
satified on the same line as the IF.
Code:i = i + 1
If i = 3 then i = 0 'you do not need an End If
PictureBox1.Picture = PictureBox2(i).Picture
[Edited by dsy5 on 10-06-2000 at 06:52 PM]
dsy5: Thank you for the correction:
What you say it TRUE
Megatron, my humbles apologies...I added a line to your code without realizing I did.
Wayne
It should be emphasized that the properties mentioned in HeSaidJoe's original response (Text or ListIndex) are all you need if only one item in the listbox can be selected - i.e., if the MultiSelect property is set to its default of "0 - None". You only need to loop through the items and check the Selected(x) property if you are allowing multi-selection (MultiSelect = Simple or Extended).