list view control

I want to know how can i know the number of items
that were selected in the list view control.

thank you in advance.
amirlAsked:
Who is Participating?
 
hSunderlinConnect With a Mentor Commented:
Dim x As Integer
Dim numSelected As Integer
For x = 1 To ListView1.ListItems.Count
  If istView1.ListItems.Itemx).Selected Then numSelected = numSelected + 1
Next x
MsgBox numSelected
0
 
Éric MoreauSenior .Net ConsultantCommented:
Have you tried this:     ListView1.SelectedItem.ListSubItems.Count
0
 
amebaCommented:
The other way can be SendMessage with parameter:
LVM_GETSELECTEDCOUNT    (LVM_FIRST + 50)
0
 
wsh2Commented:
I prefer the For Each technique.. no indexes / collection holes to worry about.. and it is just as fast.. <smile>.

<----- Code Begin ----->

Public Function xSelectedCount _
(byval ilvwListView as Listview) _
as Long

Dim itmWork as ListItem
Dim lngSelected As Long

For Each itmWork in ilvwListView

  If itmWork.Selected _
  Then
     lngSelected = lngSelected + 1
  End If
 
Next itmWork

xSelectedCount = lngSelected

End Function

<----- Code End ----->

To use this function..

Dim lngCount as Long
lngCount = xSelectedCount(Me.Listview1)

<smile>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.