|
-
Oct 19th, 2000, 08:39 AM
#1
Thread Starter
Addicted Member
Does anyone know a speedy way of determining the selected items in a ListView Control? I have a ListView that is populated with more than 6000 items and it takes too long to iterate through the entire list. There must be a faster way.
Code:
Dim intItem As Integer
Dim intCount as Integer
intCount = vewItems.ListItems.Count
For intItem = intCount To 0 Step -1
If vewItems.Listitems(intItem).Selected Then
vewItems.ListItems.Remove (intItem)
End If
Next
This works but is very slow. Still working on it.
-
Oct 19th, 2000, 08:50 AM
#2
Frenzied Member
Maybe you can send some messages to it:
Code:
Public Const LVM_GETSELECTEDCOUNT = (LVM_FIRST + 50)
Public Const LVM_GETSELECTIONMARK = (LVM_FIRST + 66)
Maybe when you have the selectedcount you could send a message with FindItem
Code:
Public Const LVM_FINDITEMA = (LVM_FIRST + 13)
Public Const LVM_FINDITEMW = (LVM_FIRST + 83)
Not sure though, look at http://www.mvps.org/vbnet/
for a lot of ListView stuff 
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 19th, 2000, 08:56 AM
#3
Thread Starter
Addicted Member
It is faster now that I am using a For...Each loop to iterate through the collection of listItems Thanks.
Always looking for a better and faster way!
-
Oct 19th, 2000, 09:05 AM
#4
Fanatic Member
You could also use the ListView.Tag ... As someone clicks in the ListView, check to see if the Item is selected or not during the click event. If the item is selected, place the item's index number and a comma in the tag (don't use spaces). You can check to see if it's in the tag by doing an instr function:
Code:
If InStr(1, ListView1.Tag, "," & ListView1.SelectedItem.Index & ",") Then
ListView1.Tag = Replace(ListView1.Tag, "," & ListView1.SelectedItem.Index & ",", ",")
Else
ListView1.Tag = ListView1.Tag & "," & ListView1.SelectedItem.Index & ","
End If
Now, granted, this might not work if 6000 items are all selected, but there is a good chance you can keep track of all the selected items without any iteration whatsoever.
Hope this helps.
-
Oct 19th, 2000, 10:39 AM
#5
Thread Starter
Addicted Member
Fast Code
This code is fast. It performed a procedure on 6000 items in 1.2 seconds.
This might be the best way to find the selected items.
Code:
Dim lstCount As ListItems
Dim lstItem As ListItem
Set lstCount = frmMain.vewItems.ListItems
For Each lstItem In lstCount
If lstItem.Selected Then
'Procedure
End If
Next
Thanks.
Always looking for a better and faster way!
-
Oct 19th, 2000, 11:27 AM
#6
Addicted Member
Why not just use the index?
nLstIndx = Listview1.SelectedItem.Index
Or just use the SelectedItem.Text to grab the listitems text etc..
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
|