C# listView增删操作

  场景: C#中使用listView控件,实现动态添加,选中删除等操作.


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

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://www.yuanjiaocheng.net/mvc/htmlhelper-validationmessagefor.html

http://www.yuanjiaocheng.net/CSharp/Csharp-operators.html

http://www.yuanjiaocheng.net/entity/add-entity-graph.html

http://www.yuanjiaocheng.net/mvc/action-filters-in-mvc.html

http://www.yuanjiaocheng.net/webapi/web-api-reqresq-format.html

http://www.yuanjiaocheng.net/CSharp/Csharp-structure.html

http://www.yuanjiaocheng.net/mvc/mvc-models.html

http://www.yuanjiaocheng.net/Java/java-features.html

http://www.yuanjiaocheng.net/webapi/create-web-api-proj.html

http://www.yuanjiaocheng.net/ASPNET-CORE/mvc-design-pattern.html

http://www.yuanjiaocheng.net/entity/update-entity.html

时间: 2024-08-01 06:06:12

C# listView增删操作的相关文章

Python字典增删操作技巧简述

Python编程语言是一款比较容易学习的计算机通用型语言.对于初学者来说,首先需要掌握的就是其中的一些基础应用.比如今天我们为大家介绍的Python字典的相关操作,就是我们在学习过程中需要熟练掌握的技巧. Python字典(Dictionary)是一种映射结构的数据类型,由无序的“键-值对”组成.字典的键必须是不可改变的类型,如:字符串,数字,tuple:值可以为任何Python数据类型. 1.新建Python字典 >>> dict = {} #新建一个空字典 >>>

List 中正确的增删操作

这个为什么要单独说的原因是,在开发中的对数据库中的增删为最基本的,但是是不是写对了就尤为重要 先来看代码: 1 public void testLoopInList(){ 2 List<String> a = new ArrayList<String>(); 3 a.add("1"); 4 a.add("2"); 5 a.add("w"); 6 for (String string : a) { 7 System.out.

c# ListView 简单操作

1. 添加数据 listView1.Items.Clear(); for (int i = 0; i < 50; i++) { ListViewItem lv = new ListViewItem(); lv.Text = "new " + i; lv.SubItems.Add("feeder " + i); listView1.Items.Add(lv); } 2.获取选择项的事件 private void listView1_SelectedIndexCh

使用Dev中的GridView进行数据增删操作

使用OracleHelper(一个C#操作Oracle数据库的工具类),连接的打开关闭全部交给OracleHelper去做. 进行增加数据信息时,新开增加数据信息的窗口,并且接受窗口的返回值,如果返回OK,对GridControl重新进行数据绑定. 1 AddForm1 add = new AddForm1(); 2 if (add.ShowDialog() == DialogResult.OK) 3 { 4 this.gridControl1.DataSource = DataSource()

关于外键的增删操作

给表添加外键必须满足2个条件,1,该表的引擎必须是InnoDB,2,必须给要添加外键的字段建立索引 create table child( cid int not null auto_increment primary key, pid int, key pid(pid), cname varchar(20)); 通过alter添加外键alter table child add constraint pids foreign key(pid) references parent(parent_i

ListView常用操作

1.设置ListView只显示一列,并且每加一条记录是向下添加的. ListView添加方法:把View属性改成Details,再Columns属性中添加一列 然后用如下代码即可实现 ListViewItem lvItem = new ListViewItem(); //lvItem.ForeColor = Color.Red;//根据需要来选择是否修改颜色 lvItem.Text = "sdfsdfsd"; this.listView1.Items.Add(lvItem);

iOS8通讯录之联系人增删查,多号码增删操作

#import <AddressBook/AddressBook.h> #pragma mark 删除一个号码 - (void)deleteLocalMarkSuccess:(void(^)(BOOL success))successBlock{ dispatch_async(dispatch_get_global_queue(0, 0), ^{ ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef records;

关于DOM树的常见增删操作

//具体关于DOM的内容可参考我的另外一篇文章"文本对象模型(Document Object Model)". 案例要点: 1.创建并增加元素节点 2.判断是否存在子节点 3.新建节点插入指定子节点的前面 4.替换子节点 5.删除指定节点 ★ 示例一  创建并增加元素节点(appendChild(childItem)) 实现代码 <ul id="ul"> <li>1</li> <li>2</li> <

DOM增删操作(select动态增加和删除以及清空)

<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script> //创建select元素 function createSelect(){ var ele = document.createElement('select'); for(var i=0;i<10;i++){ var op = new Optio