标签:
场景: C#中使用listView控件,实现动态添加,选中删除等操作.
private void addButton_Click(object sender, EventArgs e) { string item1Str = coutNumber.ToString();//第一列文本 string item2Str = coutNumber.ToString();//第二列文本 this.listView1.Items.Add(new ListViewItem(new string[] { item1Str, item2Str }));//添加一行 coutNumber++;//listView的行数递增 } private void delButton_Click(object sender, EventArgs e) { foreach (ListViewItem item in listView1.Items) { if (listView1.SelectedItems.Contains(item)) { int indexDel = listView1.Items.IndexOf(listView1.FocusedItem); if (listView1.SelectedItems.Count != 0) { listView1.Items.RemoveAt(indexDel);//删除 } } } }
效果图:
标签:
原文地址:http://blog.csdn.net/taoerit/article/details/42147873