Results 1 to 3 of 3

Thread: ListView multi-select question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    How do you properly and effeciently handle a multiple selection in the ListView?

    For example, I need to accomplish the following:

    If the user makes a multiple selection, I need to somehow store in code which items the user selected and then do some other processing with those selected items..

    Does that make sense? In other words, say there are 6 items in ListView1. Item1,Item2,Item3, etc...

    The user selects Item1, Item4, Item5, Item6. I need to beable to store each one in memory so that when the next sub is called, the sub is passed those items so it can do some processing based on the selected items...

    Also, I need to do the same with a range selection.. So that if the user clicks on Item1 and holds the shift key down and clicks on Item4, I need to beable to store any items that falls between Item1 and Item 4.

    Thanks and any help would be appreciated..

    Dan

  2. #2
    Addicted Member
    Join Date
    Jan 2000
    Location
    Fresno, California, USA
    Posts
    195
    In your event that indicates that they are finished with the listbox, put in code similar to this to build an array of selected keys:



    Dim nCnt As Integer
    Dim nSub As Integer
    Dim sKeys() As String

    For nSub = 0 To ListView1.ListItems.Count - 1
    If ListView1.ListItems(nSub).Selected = True Then
    ReDim Preserve sKeys(nCnt)
    sKeys(nCnt) = ListView1.ListItems(nSub).Key
    nCnt = nCnt + 1
    End If
    Next
    nCnt = nCnt - 1

    Your code to handle the array goes here.

  3. #3
    Addicted Member
    Join Date
    Jan 2000
    Location
    Fresno, California, USA
    Posts
    195
    I'm sorry, I made a rookie mistake. The For line should go from 1 to listitems.count as follows:


    Dim nCnt As Integer
    Dim nSub As Integer
    Dim sKeys() As String

    For nSub = 1 To ListView1.ListItems.Count
    If ListView1.ListItems(nSub).Selected = True Then
    ReDim Preserve sKeys(nCnt)
    sKeys(nCnt) = ListView1.ListItems(nSub).Key
    nCnt = nCnt + 1
    End If
    Next
    nCnt = nCnt - 1

    Sorry.


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