Results 1 to 5 of 5

Thread: Retrieving multiple rows from a list view

  1. #1

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531

    Retrieving multiple rows from a list view

    Hi all;

    I have been trying to create a function that returns values from a list view when the user selects more than one row. I figure a 2 dimensional array can do the trick, but the problem is I have not found a way to get the number of rows selected by the user. Does anyone out there know how to do this?

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Just an example:
    VB Code:
    1. Dim intLVIdx As Integer, intLVUbound As Integer
    2. Dim strBuff As String
    3.  
    4.     'Capture the UpperBound of the ListView
    5.     intLVUbound = ListView1.ListItems.Count
    6.  
    7.     'Iterate past each ListView Item and build a String Buffer of the Selected Items
    8.     For intLVIdx = 1 To intLVUbound
    9.         If ListView1.ListItems.Item(intLVIdx).Selected Then
    10.             strBuff = strBuff & ListView1.ListItems(intLVIdx).Text & vbCrLf
    11.         End If
    12.     Next


    I used a String Buffer in this case.


    Bruce.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Dim lngIndex As Long
    2.    
    3.     For lngIndex = 1 To MyListView.ListItems.Count
    4.         If MyListView.ListItems(lngIndex).Selected Then
    5.             Debug.Print "Item " & lngIndex & " is selected"
    6.         End If
    7.     Next

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Too slow Marty

    As a Function (returning an Array), like:
    VB Code:
    1. Private Function Get_Selected() As String()
    2. Dim intLVIdx As Integer, intLVUbound As Integer
    3. Dim strBuff As String
    4.  
    5.     'Capture the UpperBound of the ListView
    6.     intLVUbound = ListView1.ListItems.Count
    7.  
    8.     'Iterate past each ListView Item and build a String Buffer of the Selected Items
    9.     For intLVIdx = 1 To intLVUbound
    10.         If ListView1.ListItems.Item(intLVIdx).Selected Then
    11.             strBuff = strBuff & ListView1.ListItems(intLVIdx).Text & vbCrLf
    12.         End If
    13.     Next
    14.  
    15.     Get_Selected = Split(strBuff, vbCrLf)
    16.  
    17. End Function



    Use, like:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strArr() As String
    3.  
    4.     strArr = Get_Selected
    5.    
    6.     MsgBox strArr(0) 'etc....
    7.  
    8. End Sub






    Bruce.
    Last edited by Bruce Fox; Nov 28th, 2003 at 06:32 PM.

  5. #5

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531

    Cool

    thank-you all for your posts - I ended up going the way of creating a similar function. I am somewhat surprised however that the list view control has no built in property to give the number of rows selected. Thanks again

Posting Permissions

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



Click Here to Expand Forum to Full Width