Deleting the selected items in listview at runtime using C#
Consider a scenario where, you have a listview control in your application. Each record in the listview control holds a xmlnode object in its Tag property.
User selects few items (rcords) in listview at random and you need to save the selected node into a list and then delete the selected records from the listview at runtime.
To accomplish this scenario, the following code will help you…
//Generic list to hold the selected nodes
List<XmlNode> seletedItemsInList = new List<XmlNode>();
//working from a high index keeps lower indexes at their original value
for (int i = _ListView.Items.Count – 1; i >= 0; i–)
seletedItemsInList.Add(_ListView.Items[i].Tag as XmlNode);
Note: if you work low to high, indexes change and you do not get the right results
No comments yet.