C #: how to reference a listviewitem tag property

sorry for the noob question, but I added a tag property to the ListViewItem to act as an estimate. But now, how do I do this? I am trying to remember this tag when a double-click event occurs at runtime. I was hoping it would be something like this (stub)

MessageBox.Show(lsvItems.SelectedItem.Tag);

how do i understand this?

+3
source share
2 answers

Make sure at least one item is selected, and then you can do

 MessageBox.Show(lstView.SelectedItems[0].Tag.ToString());

If you have a specific object (e.g. an instance of Person) added to Tag, you can do

Person p = (Person) lstView.SelectedItems[0].Tag

and access instance properties

MessageBox.Show(p.Name);
+4
source

Suppose one item is selected:

 MessageBox.Show(listView1.SelectedItems[0].Tag.ToString());
+1
source

All Articles