How to count the checked ListView items 
Author Message
 How to count the checked ListView items

Question about the ListView control:
If I want to know the number of checked (not selected!) items in a ListView
control, do I have to use a API Call, or can I use a VB Function?

Greetings,
Stefan



Mon, 08 Dec 2003 03:13:09 GMT  
 How to count the checked ListView items
  Dim i As Long
  Dim lngCheckedItems As Long
  With ListView1.ListItems
    For i = 1 To .Count
        lngCheckedItems = lngCheckedItems - .Item(i).Checked
    Next
  End With

--
Mikhail Berlyant
Brainbench MVP for Visual Basic
http://www.brainbench.com
Distribution Systems Lead, Data Systems
http://www.launch.com


Quote:
> Question about the ListView control:
> If I want to know the number of checked (not selected!) items in a
ListView
> control, do I have to use a API Call, or can I use a VB Function?

> Greetings,
> Stefan



Mon, 08 Dec 2003 03:57:33 GMT  
 How to count the checked ListView items
Thanks Mikhail ,
the kind of code I was waiting for, would look like this:

Public Function CountSelected(ByRef lvwCurr As ListView) As Integer
    ' DLV.
    Dim lResult As Integer

    ' API Call functie aanroepen.
    lResult = SendMessage(lvwCurr.hwnd, LVM_GETSELECTEDCOUNT, 0, ByVal 0&)

    ' Functieresultaat doorgeven aan functiewaarde.
    CountSelected = CInt(lResult)

End Function

However, because I couldn't find a sort of "LVM_GETMARKEDCOUNT" anywhere, I
going to use your code sample.

Thanks again.



Quote:
>   Dim i As Long
>   Dim lngCheckedItems As Long
>   With ListView1.ListItems
>     For i = 1 To .Count
>         lngCheckedItems = lngCheckedItems - .Item(i).Checked
>     Next
>   End With

> --
> Mikhail Berlyant
> Brainbench MVP for Visual Basic
> http://www.brainbench.com
> Distribution Systems Lead, Data Systems
> http://www.launch.com



> > Question about the ListView control:
> > If I want to know the number of checked (not selected!) items in a
> ListView
> > control, do I have to use a API Call, or can I use a VB Function?

> > Greetings,
> > Stefan



Mon, 08 Dec 2003 06:10:32 GMT  
 How to count the checked ListView items
Why do you think it could be better?

--
Mikhail Berlyant
Brainbench MVP for Visual Basic
http://www.brainbench.com
Distribution Systems Lead, Data Systems
http://www.launch.com


Quote:
> Thanks Mikhail ,
> the kind of code I was waiting for, would look like this:

> Public Function CountSelected(ByRef lvwCurr As ListView) As Integer
>     ' DLV.
>     Dim lResult As Integer

>     ' API Call functie aanroepen.
>     lResult = SendMessage(lvwCurr.hwnd, LVM_GETSELECTEDCOUNT, 0, ByVal 0&)

>     ' Functieresultaat doorgeven aan functiewaarde.
>     CountSelected = CInt(lResult)

> End Function

> However, because I couldn't find a sort of "LVM_GETMARKEDCOUNT" anywhere,
I
> going to use your code sample.

> Thanks again.



> >   Dim i As Long
> >   Dim lngCheckedItems As Long
> >   With ListView1.ListItems
> >     For i = 1 To .Count
> >         lngCheckedItems = lngCheckedItems - .Item(i).Checked
> >     Next
> >   End With

> > --
> > Mikhail Berlyant
> > Brainbench MVP for Visual Basic
> > http://www.brainbench.com
> > Distribution Systems Lead, Data Systems
> > http://www.launch.com



> > > Question about the ListView control:
> > > If I want to know the number of checked (not selected!) items in a
> > ListView
> > > control, do I have to use a API Call, or can I use a VB Function?

> > > Greetings,
> > > Stefan



Mon, 08 Dec 2003 06:44:50 GMT  
 How to count the checked ListView items
Yes, I could be better. But I wonder if Windows supports this, meaning: Is
there a API call for getting the number of checkmarked items. I know there
is a API call for getting the number of selected items in the listview
control.

The VB code which loops trough each item of the listview control will work,
but wil be noticeable slow, especially when there are a large number of
listitems in the listview control.
Thats my problem.



Quote:
> Why do you think it could be better?

> --
> Mikhail Berlyant
> Brainbench MVP for Visual Basic
> http://www.brainbench.com
> Distribution Systems Lead, Data Systems
> http://www.launch.com



> > Thanks Mikhail ,
> > the kind of code I was waiting for, would look like this:

> > Public Function CountSelected(ByRef lvwCurr As ListView) As Integer
> >     ' DLV.
> >     Dim lResult As Integer

> >     ' API Call functie aanroepen.
> >     lResult = SendMessage(lvwCurr.hwnd, LVM_GETSELECTEDCOUNT, 0, ByVal
0&)

> >     ' Functieresultaat doorgeven aan functiewaarde.
> >     CountSelected = CInt(lResult)

> > End Function

> > However, because I couldn't find a sort of "LVM_GETMARKEDCOUNT"
anywhere,
> I
> > going to use your code sample.

> > Thanks again.



> > >   Dim i As Long
> > >   Dim lngCheckedItems As Long
> > >   With ListView1.ListItems
> > >     For i = 1 To .Count
> > >         lngCheckedItems = lngCheckedItems - .Item(i).Checked
> > >     Next
> > >   End With

> > > --
> > > Mikhail Berlyant
> > > Brainbench MVP for Visual Basic
> > > http://www.brainbench.com
> > > Distribution Systems Lead, Data Systems
> > > http://www.launch.com



> > > > Question about the ListView control:
> > > > If I want to know the number of checked (not selected!) items in a
> > > ListView
> > > > control, do I have to use a API Call, or can I use a VB Function?

> > > > Greetings,
> > > > Stefan



Tue, 09 Dec 2003 20:55:08 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Checking Checked items in Listview

2. Checking Checked items in Listview

3. Listview: check if an item in current listview

4. Count Selected Items in a Listview

5. Count selected items in ListView

6. Checked ListView Items

7. Get all checked items in ListView

8. Determing checked item in ListView

9. ListView HowTO: prevent the user from checking an item

10. Listview/Treeview item checked?

11. ListView Column Count / Subitem Count?

12. How to: Loop through all objects and count the checked check boxes

 

 
Powered by phpBB® Forum Software