不能从ListBox中的项目 [英] Cannot remove items from ListBox

查看:137
本文介绍了不能从ListBox中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图运行这个方法,我得到一个错误:



名单,这枚举势必已被修改。枚举器只能用来当列表不会改变。

 的foreach(在lstPhotos.SelectedItems VAR项)
{
lstPhotos.Items.Remove(项目);
}



如何删除所选项目吗?


解决方案

 而(lstPhotos.SelectedItems.Count!= 0)
{
lstPhotos.Items。除去(lstPhotos.SelectedItems [0]);
}


When trying to run this method I get an error:

List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.

foreach (var item in lstPhotos.SelectedItems)
{
    lstPhotos.Items.Remove(item);
}

How can I remove the selected items?

解决方案

while(lstPhotos.SelectedItems.Count != 0)
{
    lstPhotos.Items.Remove(lstPhotos.SelectedItems[0]);
}

这篇关于不能从ListBox中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆