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