Reliable Way To Cancel ItemCheck Event On CheckedListBox

.net, c#, vb.net

Solution

It is easy to do with the ItemCheck event. Just set the value back. Like this:

    private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) {
        if (someCondition) e.NewValue = e.CurrentValue;
        else {
            // Regular stuff
            //...
        }
    }

Problem

Does anyone know of a reliable way to cancel the ItemCheck event on a CheckedListBox? I am in a situation where the ItemCheck event should basically discard changes on a form, however, if the person decides to cancel the discard I would like the ItemCheck event not to fire so as not to change anything.

Original source