对于C#和更重要的是Visual Studio 2012,我都是一个EXTREME新手,所以对不起,如果这看起来像一个简单的问题。所以我正在做一个To Do List应用程序,作为我的第一个使用VS2012的小项目。我有一个名为'checkedListBox1'的CheckedListBox和一个名为'markButton'的按钮,用于删除标记(或选中)的项目。我已经写了下面的代码,但正如你在我的评论中看到的那样,它确实有点奇怪:从我拥有的已选项目集合中删除其他所有已检查的项目。Visual Studio 2012 C#:删除CheckedListBox中的所有*检查项目
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());
}
}
那么你想删除所有选中的项目? –