Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting selected item on List Box

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How can I know if there is a selected item on a list box?
I thought this worked as for the comboboxes, ie, the ListIndex property would return -1. But now I figured that this property will return 0 if there is no selected item or if the first one is selected, so I don't really know how can I detect if the list box as a selected item or not. Anyone can help?
 
Hi,

You can loop through the list to detect which items are selected:

for i=0 to list1.listcount-1
if list1.selected(i) then msgbox("Item "& cstr(i) &" is selected."
next i

Maybe there's easier way...

:) Sunaj
 
If there is an easier way, I've not found it. In addition, if you would like to know what the actual text of the selected item is, rather than its index, change the IF statement between the For Next to:

If List1.Selected(i) Then msgbox("Item " & List1.List(i) & " is selected."

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top