public void SetItemCheckState(int index, CheckState value)
{
// Check index actually exists
if ((index < 0) || (index >= Items.Count))
throw new ArgumentOutOfRangeException("index", "index out of range");
// Is the new state different from the current checked state?
CheckState checkedState = CheckedItems.GetCheckedState(index);
if (value != checkedState)
{
// Give developers a chance to see and alter the change
ItemCheckEventArgs ice = new ItemCheckEventArgs(index, value, checkedState);
OnItemCheck(ice);
// If a change is still occuring
if (ice.NewValue != checkedState)
{
CheckedItems.SetCheckedState(index, ice.NewValue);
_listBox.Invalidate();
}
}
}