ListView ItemCheck is always one behind?? VB

  • Thread starter Thread starter Patrick Dugan
  • Start date Start date
P

Patrick Dugan

I am using Visual Studio 2005 (visual basic) and Compact Framework 2.0

I have a ListView that will contain several Items. The ListView has
checkboxes enabled.
Whenever the user clicks on a checkbox to change it (check or uncheck) I
want to indicate
how many items are currently checked. This routine below looks correct to
me, but each time
I check or uncheck the number reported back is always the previous count and
not the current count of items that are checked.


Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck

Dim CheckCount As Integer
Dim NItem As ListViewItem
CheckCount = 0

For Each NItem In ListView1.Items

If NItem.Checked Then

CheckCount = CheckCount + 1

end if

Next

Msgbox("Number of items checked are: " & CheckCount)

End Sub

Can anybody tell me why the CheckCount is always behind? For example if no
items are checked and then I check
one item, the checkcount is still zero. When I uncheck that same item then
the checkcount is now 1.

It is like the state of being checked or unchecked for any item happens
after the ItemCheck event in the ListView.

I looked for an ItemChecked event but no such event shows.

Help!


Patrick Dugan
 
I would guess that's because this event is firing before data has been
changed.

Consider event argument to correct this. To do use state from arguments for
item which is about to change instead of data you're getting from
enumerator.


Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
Back
Top