VB.Net:Counting total CheckBox ticked in ListView

Lennie

New member
Joined
Feb 9, 2007
Messages
3
Programming Experience
Beginner
Hi there,
I am a newbie to Vb.Net with VB6 background. I am using ListView to display rows of data with checkbox to enable user to make selection by ticking in the checkbox. When the form is closed I have a method which will loop thru the ListView to count how many checkbox were ticked. Apparently, the routine counted all the rows instead of just the ticked checkbox.

My sample script attached.
Private Function FCheckBox()

Dim itmx As ListViewItem
Dim lw As ListView = Me.ListSelection
Dim lngPCheckCount as integer = 0


With lw
For Each itmx In .Items
If .CheckedItems(1).Checked = True Then
lngPCheckCount += 1
End If
Next
End With

End Function
 

Attachments

  • CheckListBox.JPG
    CheckListBox.JPG
    16.3 KB · Views: 39
You are only checking if second checkeditem is checked, which from screen it is.

You can get the count directly:
VB.NET:
Expand Collapse Copy
dim cnt as integer = [SIZE=2]ListView1.CheckedItems.Count[/SIZE]
 
Back
Top