无法从列表框中删除项目 [英] Cannot remove items from ListBox

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

问题描述

尝试运行此方法时出现错误:

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);
}

如何删除选定的项目?

推荐答案

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

这篇关于无法从列表框中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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