I’m working on a .NET Windows Forms application. I have an event handler procedure for the CheckedListBox control that’s supposed to remove a checkBox from the list if it is unchecked. I got that part working, but the problem is that the next checkBox, which is supposed to be checked, automationally becomes unchecked when I do that.
I have tried ‘manually’ removing all elements from the CheckedListBox and adding them again, making sure they are checked, but the next checkbox remains unchecked.
This is very frustrating.
Is there something wrong with my code or is this a bug?
private void checkedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.CurrentValue == CheckState.Checked)
{
checkedListBox.Items.RemoveAt(e.Index);
}
}
I found a way to solve the problem. It’s a bit of a hack, but it works.
I just provided a MouseUp event handler procedure and inside it looped through the checkedListBox’s Items, setting unchecked items to checked.