When Calls to a CheckedListBox's SetItemChecked Method acting Don't Work

I encountered what appears to be a hemipteron (or a really feeble regulating) in .NET present time on the job with a CheckedListBox control. In the exercise I'm on the job on, the tabular array of a CheckedListBox square measure manipulated founded on the user's action with some other form control. Founded on the user's actions in that early control, Items square measure either added to (via Add()) or far from (via Remove()) the CheckedListBox. This is beautiful straightforward.
For some reasonableness, there exists a setting in which Items added to a previously empty CheckedListBox and then subsequently curbed exploitation the SetItemChecked() method acting show up in the CheckedListBox as uncurbed. Present is many try mark demonstrating my usance of the varied methods:
// supply the item
myCheckedListBox.Items.Add(itemToAdd);
// find the newly added particular and change its CheckState to checked
myCheckedListBox.SetItemChecked(myCheckedListBox.Items.IndexOf(itemToAdd), true);
In my special exercise, the subdivision calls square measure successful within a loop, where itemToAdd represents a several particular upon each repeating. What I see in my exercise is that, if myCheckedListBox is empty (i.e. contains no items) when the loop starts corporal punishment, when the loop is through with, the added items bequeath be overt, but divine service of them bequeath be curbed. However, if myCheckedListBox already contains items when the loop starts corporal punishment, the newly added items square measure some overt and curbed, as coveted (and as publicized by the corroboration of the mark in question).
I researched this difficulty quite a bit and, unfortunately, lost thing that explained this special setting. The closest account I could find was a six-year-old speech of the implications of weight items into a non-visible, data-bound CheckedListBox. Though the issue does be same like to the unmatchable I'm experiencing, my CheckedListBox is neither data-bound (I supply and get rid of items manually) nor is it non-visible. Nevertheless, I feel the equivalent symptom.
Whether the difficulty is really a regulating of the .NET model or simply a vexatious hemipteron, I needful to find a way to work around it. Luckily, I was healthy to find a relatively direct workaround. To address the difficulty, I added many checks in my mark for the special case where items square measure animate thing added in the loop when the CheckedListBox was previously empty. If this setting is encountered, aft the loop finishes corporal punishment, I've added many mark that iterates done the newly added items in some other loop and sets their state to curbed again:
// repeat done every items
for (int i = 0; i < myCheckedListBox.Items.Count; i++)
{
// change the state to checked
myCheckedListBox.SetItemChecked(i, true);
}
It seems unnecessary to do so, of course, but something astir this occurrence outside of the letter of the alphabet loop implementation leads to the coveted results. And in the end, it's every astir achieving the coveted results, right?