Chad
Chad

Reputation: 24679

WinForm CheckListBox problem with ItemCheck event

When the checked state of a check box change, I would like to know what the new value is. his is what I am doing:

Friend WithEvents clstTask As System.Windows.Forms.CheckedListBox

Private Sub clstTask_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles clstTask.ItemCheck
    Dim SelectedCheckState As CheckState = clstTask.GetItemCheckState(clstTask.SelectedIndex)
End Sub

However, the value of the SelectedCheckState variable is not accuratley reflecting the new state. I think it is showing the current state before the click, as if this were a "Before_CheckChanged" event handler.

The Check box is a 3 state check box, (Checked, UnChecked, Undetermined). Do I have to write ugly code that assumes that if the CheckState returned is state "X" that the CURRENT state must be Y?

Upvotes: 0

Views: 1187

Answers (2)

tster
tster

Reputation: 18237

Check out ItemCheckEventArgs.NewValue and ItemCheckEventArgs.CurrentValue. This is why that parameter is there ;)

Upvotes: 1

Jon Seigel
Jon Seigel

Reputation: 12401

The ItemCheckEventArgs exposes properties CurrentValue and NewValue.

Upvotes: 3

Related Questions