先把选中的index记下来,然后从后往前删除可以的。代码如下:
private int [] SelectIndex()
{
int [] selIndex;
int iIndex = 0;
if (lvLocal.SelectedIndices.Count == 0)
{
return null;
}
selIndex = new int[lvLocal.SelectedIndices.Count];
for (int i = 0; i < lvLocal.SelectedIndices.Count; i++)
{
selIndex[iIndex++] = lvLocal.SelectedIndices[i];
}
return selIndex;
}
int [] selIndex = SelectIndex();
if (selIndex == null || selIndex.Length < 1)
{
return;
}
for (int i = selIndex.Length - 1; i >= 0; i--)
{
lvLocal.Items.RemoveAt(selIndex[i]);
}