Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Iterate through a multiselect ListView (2002/SP2)

    I'm new to using the ListView in Access. I'm having trouble iterating through the selected items of a multiselect ListView. I'm completely confused because in some places I look for information it refers to SelectedItem method and in others it refers to SelectedItems. Basically I want to iterate through the selected items collection and display the item key or a column value and display it in a msgbox. I'm using the 6.0 version of the ListView control. Could any of you provide an example of what I need to declare right down to the For...Next statement?

    Thanks,
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Iterate through a multiselect ListView (2002/SP2)

    SelectedItem refers to the first selected item in a listview. To iterate through all selected items, use the Selected property:
    <code>
    Dim i As Integer
    ' Loop through list items
    For i = 1 To Me.lvwList.ListItems.Count
    ' Is item selected?
    If Me.lvwList.ListItems(i).Selected Then
    ' Do something with it
    MsgBox Me.lvwList.ListItems(i).Text
    End If
    Next i
    </code>
    Replace the MsgBox statement with the code you want to apply to selected items.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Iterate through a multiselect ListView (2002/SP2)

    By the way, the MSDN documentation for the ListView control is here: ListView Control.

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Iterate through a multiselect ListView (2002/SP2)

    That makes complete sense now. Once again, I thank you for your time.

    Don

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •