C# listview中如何同时删除多行内容

2024-11-22 13:26:31
推荐回答(4个)
回答1:

VS2008直接打开.

主要代码


foreach (ListViewItem item in this.listView1.CheckedItems)
{
this.listView1.Items.Remove(item);
}


回答2:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//动态生成选项10个
for (int i = 1; i < 11; i++)
{
ListViewItem litem = new ListViewItem() { Text = "item"+i };
listView1.Items.Add(litem);
}
} private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i {
if (listView1.Items[i].Checked)
{
listView1.Items.RemoveAt(i);
i--;
}
}
}
}
}

回答3:

foreach (ListViewItem item in listView1.SelectedItems)

{

if (item.Selected)

{

item.Remove();

}

}

引用: 网页链接

回答4:

用一个循环的函数!选中的循环 没有选中的不循环!!!