【发布时间】:2014-02-11 09:56:00
【问题描述】:
我是 C# 以及更重要的是 Visual Studio 2012 的极端新手,如果这似乎是一个简单的问题,我深表歉意。所以我正在制作一个待办事项列表应用程序作为我使用 VS2012 的第一个小项目。我有一个名为“checkedListBox1”的 CheckedListBox 和一个用于一次性删除标记(或选中)项目的按钮,名为“markButton”。我编写了以下代码,但正如您在我的评论中看到的那样,它做了一些奇怪的事情:从我拥有的已检查项目集合中删除所有其他已检查项目。
private void markButton_Click(object sender, EventArgs e)
{
// create a collection of the checked items in the to do list
// then remove each of them.
// **** ERROR: It deletes every other checked item
// so it deletes indeces 0..2..4..6... each time.
CheckedListBox.CheckedItemCollection checkedItems = checkedListBox1.CheckedItems;
for (int i = 0; i < checkedItems.Count; i++)
{
checkedListBox1.Items.Remove(checkedItems[i].ToString());
}
}
【问题讨论】:
-
那么你想删除所有选中的项是什么?
标签: c# visual-studio-2012 checkedlistbox items removeall