- when i try to remove ListBox item(ListItem) its giving error
error :
List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.
i have only ListItem objects in my ListBox and my code as follows
foreach (ListItem removeitem in listBox1.SelectedItems)
{
listBox1.Items.Remove(removeitem);
}
或者
foreach (string Titem in xml_target.SelectedItems)
{
xml_target.Items.Remove(Titem);
}
错误信息:
List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.
解决办法:
- while(listBox1.SelectedItems.Count!=0)
{
listBox1.Items.Remove(listBox1.SelectedItems[0]);
}
while (xml_target.SelectedItems.Count != 0)
{
xml_target.Items.Remove(xml_target.SelectedItems[0]);
}
阅读(2625) | 评论(0) | 转发(0) |