How can we access the items added to a ListView?
The thing I have to do is: add an item to the list view. I want to check if the item to add to the listview is alrea
The following will help to locate a ListViewItem
within the ListView
control once you've added it:
string key = ;
if (!theListViewControl.Items.ContainsKey(key))
{
item = theListViewControl.Items.Add(key, "initial text", -1);
}
// now we get the list item based on the key, since we already
// added it if it does not exist
item = theListViewControl.Items[key];
...
Note
The key
used to add the item to the ListView
items collection can be any unique value that can identify the ListViewItem
within the collection of items. For example, it could be a hashcode value or some property on an object attached to the ListViewItem
.