As follows:
for(int i=checkedListBox1.Items.Count;i>=0;i--)
{
if(chtest.GetItemCheckState(i)==CheckState.Checked)
{
checkedListBox1.Items.RemoveAt(i);
}
}
for(int i=checkedListBox1.Items.Count;i>=0;i--)
{
if(chtest.GetItemCheckState(i)==CheckState.Checked)
{
checkedListBox1.Items.RemoveAt(i);
}
}
for(int i=checkedListBox1.Items.Count;i>=0;i--)
{
if(checkedListBox1.GetItemCheckState(i)==CheckState.Checked)
{
checkedListBox1.Items.RemoveAt(i);
}
}
{
this.checkedListBox1.Items.RemoveAt(this.checkedListBox1.CheckedIndices[0]);
}i 不用++
每次remove CheckedIndices[0]
因为每删除一项,顺序就变了