C # add or delete a listView,

Source: Internet
Author: User

C # add or delete a listView,

Scenario: Use the listView control in C # To dynamically add, select, delete, and perform other operations.

 
12345678910111213141516171819202122 private void addButton_Click(object sender, EventArgs e){     string item1Str = coutNumber.ToString(); // The first column of Text     string item2Str = coutNumber.ToString(); // The second column of Text     this .listView1.Items.Add( new ListViewItem( new string[] { item1Str, item2Str })); // Add a row     coutNumber++; // The number of rows in the listView increases} 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); // Delete             }         }     }}

 

Reference page:

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.