lee88
asked on
detect which (multiple) items are selected in listview ?
I have a listview, lvwInclude, that has a bunch of line items in it. MultiSelect property is enabled.
I click on one item, then hold shift and click another to select multiple line items.
But, when I execute this loop (by clicking on a cammand button), the result is that the nSelectedCount count is only one, which indicates that only one item is selected?
'************************* ********** *
Private Sub Command1_Click()
Dim nSelectedCount As Integer
Dim lItem As ListItem
'See if multiple listview items are selected:
nSelectedCount = 0
For Each lItem In lvwInclude.ListItems
If lItem.Selected Then
nSelectedCount = nSelectedCount + 1
End If
Next
Debug.Print nSelectedCount
End Sub
'************************* **********
What do I have to do to count how many line items are multi-selected?
I click on one item, then hold shift and click another to select multiple line items.
But, when I execute this loop (by clicking on a cammand button), the result is that the nSelectedCount count is only one, which indicates that only one item is selected?
'*************************
Private Sub Command1_Click()
Dim nSelectedCount As Integer
Dim lItem As ListItem
'See if multiple listview items are selected:
nSelectedCount = 0
For Each lItem In lvwInclude.ListItems
If lItem.Selected Then
nSelectedCount = nSelectedCount + 1
End If
Next
Debug.Print nSelectedCount
End Sub
'*************************
What do I have to do to count how many line items are multi-selected?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use this code:
Dim nSelectedCount As Integer, X As Integer
nSelectedCount = 0
For X = 0 To lvwInclude.ListCount - 1
If lvwInclude.Selected(X) Then
nSelectedCount = nSelectedCount + 1
End If
Next X
Label1 = Str$(nSelectedCount)
Dim nSelectedCount As Integer, X As Integer
nSelectedCount = 0
For X = 0 To lvwInclude.ListCount - 1
If lvwInclude.Selected(X) Then
nSelectedCount = nSelectedCount + 1
End If
Next X
Label1 = Str$(nSelectedCount)
ASKER
Leithauser: I get error: Listview does not have a ListCount property
There is no Listview in my code
ASKER
the original question is:
What do I have to do to count how many line items are multi-selected
IN MY LISTVIEW
What do I have to do to count how many line items are multi-selected
IN MY LISTVIEW
<<the original question is:
What do I have to do to count how many line items are multi-selected
IN MY LISTVIEW>>
Sorry, I misread the question. I thought it was a listbox.
What do I have to do to count how many line items are multi-selected
IN MY LISTVIEW>>
Sorry, I misread the question. I thought it was a listbox.
Set HideSelection = False. Your PropertyPage shows it checked.
ASKER
Leithauser: no prob. Is there a similar approach for a listview?
danaseaman: I have tried HideSelection both ways. I currently have it unchecked, but my nSelectedCount still comes up as 1 instead on the count of selected items. However, with HideSelection unchecked, I can see the selected items as highlighted after the ListView loses focus.
danaseaman: I have tried HideSelection both ways. I currently have it unchecked, but my nSelectedCount still comes up as 1 instead on the count of selected items. However, with HideSelection unchecked, I can see the selected items as highlighted after the ListView loses focus.
ASKER
You were correct. Nothing wrong with the code. I had cut-and-pasted the name of a different listview by mistake. Thanks for your help.
ASKER
proppg.jpg