Since an 'ItemCheck Event is always (well, it should be: see note below) followed by a ValueChanged Event (yes, that doesn't make a lot of sense, but that's the way it is), you can do this to make sure your 'sum calculation is always current.
This example assumes you have a multi-line TextBox on a Form, 'textBox1, and a CheckedListBox, 'checkedListBox1:
private bool IsCheckedChanged = false;
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
IsCheckedChanged = true;
textBox1.Text += "change in Item CheckState" + Environment.NewLine;
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text += "index changed" + Environment.NewLine + Environment.NewLine;
}
private void checkedListBox1_SelectedValueChanged(object sender, EventArgs e)
{
textBox1.Text += "value changed" + Environment.NewLine;
if (IsCheckedChanged)
{
int sum = 0;
foreach (var chkItem in checkedListBox1.CheckedItems)
{
sum += Convert.ToInt32(chkItem);
}
textBox1.Text += "Sum: " + sum.ToString() + Environment.NewLine;
IsCheckedChanged = false;
}
}
If click Items rapidly in the CheckedListBox, and examine the content written to the TextBox, you will probably observe some instances where there is an irregularity in the way the various Events are fired. Yep, the Control ain't perfect !
But, most of the time a change in any Item's CheckState will trigger a ValueChanged Event, and you can evaluate the state of all CheckedItems reliably.
In using the native Windows Controls (or third-party Controls !), I strongly suggest you experiment with writing simple EventHandlers for the Events you are interested in that write some meaningful output to the Console or to a TextBox. Learning, and understanding, the order of execution, and inter-dependencies of the Events, is, imho, the only way to really be sure you understand how to use the given Control efficiently, and without creating subtle errors that are hard to understand/debug.