By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,693 Members | 1,650 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,693 IT Pros & Developers. It's quick & easy.

CheckedListBox Questoin

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
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

Nov 21 '05 #2

P: n/a
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

"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
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

"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
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


Nov 21 '05 #3

P: n/a
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

"Mike McIntyre" <mi****@dotnetshowandtell.com> wrote in message
news:Oe**************@TK2MSFTNGP11.phx.gbl...
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

"Jerry Spence1" <je**********@somewhere.com> wrote in message
news:41***********************@ptn-nntp-reader04.plus.net...
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


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.