Is there a checkedListBox ItemUnchecked/CheckChanged event of some kind?

186 Views Asked by At

I know that there is a checkedListBox event called ItemChecked and I think there's a CheckChanged event for individual checkboxes, but is there an ItemUnchecked or CheckChanged event counterpart for a checkedListBox? If so, how would I subscribe to it and implement/use it?

When I use the "NewValue" method recommended, it just spits back an error and states: "'EventArgs' does not contain a definition for 'NewValue' and no accessible extension method 'NewValue' accepting a first argument of type 'EventArgs' could be found (are you missing a using directive or an assembly reference?)". Does anyone have any advice?

My goal is to create a piece of code as a counterpart to the ItemChecked event so that if the user unchecks a box, it will undo the effect the checking event had.

Example of what I want to be able to do:

private void checkedListBoxBasics_ItemUnCheck(object sender, EventArgs e)
        {
            //The variable "index" was instantiated previously in the code.
            //get index of checked box and set variable index to that
            index = checkedListBoxBasics.SelectedIndex;

            if (index == 0)
            {
                updateResourcesUncheck("checkedListBoxBasics", 100000, 0, 0, 0, 0, 0, 0, 0);
            }

        }
1

There are 1 best solutions below

5
AudioBubble On
    private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
    {
        // get the NewValue
        bool isChecked = (e.NewValue == CheckState.Checked);

        // if checked
        if (isChecked)
        {
            // apply event for isChecked
        }
        else
        {
            // apply event for unChecked
        }
    }