VS2008直接打开.
主要代码
foreach (ListViewItem item in this.listView1.CheckedItems)
{
this.listView1.Items.Remove(item);
}
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--;
}
}
}
}
}
foreach (ListViewItem item in listView1.SelectedItems)
{
if (item.Selected)
{
item.Remove();
}
}
引用: 网页链接
用一个循环的函数!选中的循环 没有选中的不循环!!!