Link to home
Start Free TrialLog in
Avatar of amirl
amirl

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of hSunderlin
hSunderlin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Éric Moreau
Have you tried this:     ListView1.SelectedItem.ListSubItems.Count
The other way can be SendMessage with parameter:
LVM_GETSELECTEDCOUNT    (LVM_FIRST + 50)
Avatar of wsh2
wsh2

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>