且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从列表视图中删除多个选定的项目

更新时间:2022-12-26 19:53:48

尝试使用BeginUpdate和EndUpdate来控制ListView的更新

Try using BeginUpdate and EndUpdate to control the update of your ListView

try
{
    listview2.BeginUpdate();
    foreach (ListViewItem item in this.listview2.SelectedItems)
    {
        this.listview2.Items.Remove(item);
    }
}
finally
{
    this.listview2.EndUpdate();
}


您也可以尝试
you can also try it
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 />