Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reliable Way To Cancel ItemCheck Event On CheckedListBox

Tags:

c#

.net

vb.net

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.

like image 694
test Avatar asked Dec 09 '22 00:12

test


1 Answers

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
            //...
        }
    }
like image 121
Hans Passant Avatar answered Jan 07 '23 16:01

Hans Passant