本文介绍了从列表视图中删除多个选定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我使用此代码从列表视图中删除多个项目,但是问题是它一次只能删除一个项目.
所以请帮我删除多个选定项目的用途.
hello, i use this code for delete multiple items from listview, but problem is that it delete only one item at a time.
so please help me what is use to delete multiple selected items.
for (int i = listView2.SelectedItems.Count - 1; i >= 0; i++)
{
if (listView2.Items[i].Selected)
{
listView2.Items.Remove(listView2.Items[i]);
}
}
推荐答案
try
{
listview2.BeginUpdate();
foreach (ListViewItem item in this.listview2.SelectedItems)
{
this.listview2.Items.Remove(item);
}
}
finally
{
this.listview2.EndUpdate();
}
while (listView2.SelectedItems.Count > 0)
{
listView2.Items.Remove(listView2.SelectedItems[0]);
}
<br />
<pre lang="cs">foreach (ListViewItem ListItem in listView1.Items)<br />
{<br />
if (ListItem.Selected == true)<br />
listView1.Items.Remove(ListItem);<br />
}</pre><br />
<br />
这篇关于从列表视图中删除多个选定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!