网上找了半天,没找到能用的。

不过倒是找到了思路。

正着一个个删,是删不掉滴,删一个后,下一个的index就变了。INDEX是空不了的。

只能反着移。

先写了一个笨一点的方法,循环最多次,倒是能实现一次性全删除,不过循环过多。

for (int i = checkedListBox1.Items.Count-1 ; i > -1; i--)
{
if (checkedListBox1.GetItemChecked(i))
{
checkedListBox1.Items.RemoveAt(i);
}
}

用CheckedItems,CheckedIndices实现,有多少个被选中,就循环多少次。

for (int i = checkedListBox1.CheckedItems.Count-1; i >-1; i--)
{
checkedListBox1.Items.RemoveAt(checkedListBox1.CheckedIndices[i]);
}

相关文章:

  • 2022-12-23
  • 2021-08-14
  • 2022-01-10
  • 2022-12-23
  • 2022-01-30
  • 2022-02-19
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案