Hi, I assume this have been asked and answered before, but can't seem to find any info on this.. How do you get the number of selected items in a listview without having to loop through all the records?
Thanks
John
Printable View
Hi, I assume this have been asked and answered before, but can't seem to find any info on this.. How do you get the number of selected items in a listview without having to loop through all the records?
Thanks
John
I think they only way you can do it is to loop there the items in the listview and check their selected prop.
If you have to loop through them to check their property, the what is the SelCount property for? :D
But if you really wanted to do it with a loop...
Dim num As Integer
num = 0
For x = 0 To List1.ListCount - 1
If List1.Selected(x) = True Then
num = num + 1
End If
Next
MsgBox num
Hi, I actually found this thread that have a solution.. Seemed to work..
http://forums.vb-world.net/showthrea...threadid=13921
Second last reply..
John
use this.
ListBox.ItemsSelected.Count
http://www.vbforums.com/attachment.p...id=47243&stc=1
The code you posted is not VB6 code. In VB6 the answer is List1.SelCount
And furthermore, this thread is almost 10 years old! There is no need to post replies to old/dead threads.
Wow, I didn't notice:)
Kind of fun to respond to it anyway. I needed a refresher course. Build a form with a label and a list box. Then apply this code:
Code:Private Sub Form_Load()
' Sample Data
For I = 1 To 100
List1.AddItem I
Next
End Sub
Private Sub List1_Click()
Dim SlCount As Integer
For I = 0 To List1.ListCount - 1
If List1.Selected(I) = True Then SlCount = SlCount + 1
Next
Label1.Caption = SlCount & " Item(s) Selected"
End Sub