|
-
Sep 22nd, 2000, 11:59 AM
#1
Thread Starter
Frenzied Member
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
-
Sep 22nd, 2000, 01:11 PM
#2
Addicted Member
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.
-
Sep 25th, 2000, 12:55 PM
#3
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|