码迷,mamicode.com
首页 > Windows程序 > 详细

C# listView增删操作

时间:2017-02-19 15:46:36      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:click   object   状态   graph   模式   structure   filter   comment   ted   

  场景: 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

C# listView增删操作

标签:click   object   状态   graph   模式   structure   filter   comment   ted   

原文地址:http://www.cnblogs.com/woquwoqu/p/6415703.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!