Selected item in a listbox

Rookie
09-06-2003, 05:45 AM
how do i find the selected item in a listbox???

vbfan
09-06-2003, 05:56 AM
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
MsgBox "Item Nr." & i + 1 & " is selected."
MsgBox List1.Text
Exit For
End If
Next i
End Sub

Kaluriel
09-06-2003, 06:01 AM
why so much code? List1.ListIndex :P

Mad_Kitten
09-06-2003, 06:26 AM
and if you want the text of the selected item use:
list1.text

OnErr0r
09-06-2003, 09:30 AM
Kaluriel is correct, and I just thought I'd add, it's possible to have no selection in a listbox too. In which case the listindex is -1.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum