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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Obtain a list of selected items in a multi-select listbox

Status
Not open for further replies.

HerbAndEdnaWeinstein

Technical User
Apr 30, 2003
104
US
hi, i've got a fmMultiSelectMulti listbox called LayerTo. I'm trying to use this code to return a list of all selected items in it.

when i declare LayerTo as fmMultiSelectSingle, the debugging text returns without a problem. when i declare it as fmMultiSelectMulti, however, no debugging text returns.

any ideas?

thanks in advance,
rs


Public Sub LayerTo_Click()

Isubset = -1

For Iprimary = 0 To (pMap.LayerCount - 1)
'initialize 'selection set (everything is -1)
LStatus5(Iprimary) = -1
Next Iprimary

For Iprimary = 0 To (pMap.LayerCount - 1)
If LStatus2(Iprimary) > -1 Then
If LayerTo.Selected(LStatus2(Iprimary)) Then
'if part of applicable set
Isubset = Isubset + 1
LStatus5(Iprimary) = Isubset
Debug.Print ("layerto: " & LStatus1(Iprimary) & " , " & LStatus2(Iprimary) & " , " & LStatus3(Iprimary) & " , " & LStatus5(Iprimary))
End If
End If
Next Iprimary

End Sub
 
Here is some code to examine:
[blue]
Code:
Private Sub CommandButton1_Click()
Dim i As Integer
  ListBox2.Clear
  For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) Then
      ListBox2.AddItem ListBox1.List(i)
    End If
  Next i
End Sub
[/color]

Drop 2 list boxes and a command button on a form, give ListBox1 some data (e.g. with the RowSource property) and run the form. Select a couple of items and click the button.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top