In my windows forms project written in C# I try to clear a CheckedListBox after the last Item is checked.
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (checkedListBox1.CheckedItems.Count + 1 == checkedListBox1.Items.Count)
{
checkedListBox1.Items.Clear();
}
}
In this example, the program would throw a NullReferenceException, after I check the last item.
Could somebody explain why this is happening and how I can handle this?
Thanks in advance!