初心者としては賢明で知的な仕事ではありませんが、最終的には私の問題を解決しました.
private void CheckedListBox_ItemCheck(Object sender, ItemCheckEventArgs e)
{
int count = 0;
if (e.NewValue.ToString() == "Checked")
{
// first get all the checked items
foreach (object checkeditem in CheckedListBox.CheckedItems)
{
string checkItem = CheckedListBox.GetItemCheckState(CheckedListBox.Items.IndexOf(checkeditem)).ToString();
if (checkItem == "Checked")
{
count = count + 1;
}
}
// Now, below is the most important part considering the remark on MSDN
// "The check state is not updated until after the ItemCheck event occurs."
count = count + 1; // Plus 1 as the NewValue was Checked
labelCount.Text = "You have selected " + count + "Items.";
}
else if (e.NewValue.ToString() == "Unchecked")
{
// first get all the checked items
foreach (object checkeditem in CheckedListBox.CheckedItems)
{
string checkItem = CheckedListBox.GetItemCheckState(CheckedListBox.Items.IndexOf(checkeditem)).ToString();
if (checkItem == "Checked")
{
count = count + 1;
}
}
// Now, below is the most important part considering the remark on MSDN
// "The check state is not updated until after the ItemCheck event occurs."
count = count - 1; // minus 1 as the NewValue was Unchecked,
labelCount.Text = "You have Selected " + count + "Items.";
}
}
このコードに関するコメントをいただければ幸いです。