CheckedListBox Questoin

J

Jerry Spence1

I am trying to capture when an item in the CheckedListBox occurs.

I am using the event:
CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As
System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox.ItemCheck

However, this fires before the item is actually checked. So to get over this
problem I tried:

If e.CurrentValue = CheckState.Unchecked Then

e.NewValue = CheckState.Checked

Else

e.NewValue = CheckState.UnChecked

End If

However, setting the e.NewValue doesn't actually seem to change the checked
state (I'm not really sure what it does do!)

I then tried:

If e.CurrentValue = CheckState.Unchecked Then

CheckedListBox.Checked(e.Index,True)

Else

CheckedListBox.SetItemChecked(e.Index, False)

End If

However, this obviously then fires the event again and the who thing goes
into loop.

Does anyone know a way round this?

-Jerry
 
M

Mike McIntyre

The ItemCheckEventArgs contains both the 'before' and 'after' states of the
CheckBox. You do not need to set the state of the CheckBox.

If e.NewValue = CheckState.Checked
' The new CheckState is Checked - add code to react.
Else
' The new CheckState is Unchecked - add code to react.
End If


--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
 
J

Jerry Spence1

Say it is in the Unckecked state. You then click on it to put it into the
checked state, and the event is fired. As far the as the event is concerned,
it is still unckecked. It doesn't visibly become checked until after the
event has completed.

- Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top