Chinaunix首页 | 论坛 | 博客
  • 博客访问: 827264
  • 博文数量: 101
  • 博客积分: 1311
  • 博客等级: 中尉
  • 技术积分: 1191
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-25 12:15
文章分类

全部博文(101)

文章存档

2012年(101)

分类: 嵌入式

2012-06-12 23:31:13

  • 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]);

}

阅读(2630) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~