I have a list box set to Multiselect = 1. Now I want to read through the collection of selected rows (e.g., for each...in...). However, I cannot find this method in any documention. Can someone help me with an example please. :)
Printable View
I have a list box set to Multiselect = 1. Now I want to read through the collection of selected rows (e.g., for each...in...). However, I cannot find this method in any documention. Can someone help me with an example please. :)
Loop thru the ListBox, and if the current Item is .Selected, then do whatever.
I post some pseudo code.
You can use Sendmessage api function. Here is a sample:
Quickly Retrieve Multiple List Box Selections
Along these line:
VB Code:
Private Sub Command1_Click() Dim intCount As Integer Dim intIdx As Integer intCount = List1.ListCount - 1 For intIdx = 0 To intCount If List1.Selected(intIdx) Then MsgBox List1.List(intIdx) Next End Sub
Edit: If you intend to delete the selected items, then you must pass thru the ListBox backwards (intCount to 0 Step -1).
The code example was a big help. Thank you. I guess I was incorrect in remembering that the selected items create a collection that can be worked with a "for all...in..." type of statement. I will use the example you listed.