I am listing set of table items(only names) in List View. I enabled checkbox property of ListView. I displayed all items as Large icons. I want to attach a key(id) for that items for further processing on that items.. If any idea , please reply
Use the ListViewItem.Name property. Poorly named, it is actually the key. The one you can pass to ListView.Items.IndexOfKey() or ListView.Items["key"].
You should use the Tag
property for things like that.
Gets or sets the object that contains data about the control.
You can set your id or any other object
to the ListItem
you want.
Add the Item
ListViewItem myItem = new ListViewItem();
myItem.Tag = 1; // or any other object
listView1.Items.Add(myItem);
Use the index
private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
ListViewItem myItem = e.Item;
int index = (int) myItem.Tag; // cast to your object type, int in this case
// use the index
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With