c#: how to reference the tag property of a listviewitem
sorry for the noob question, but I added a tag property to a ListViewItem to act as a valuemember. But now how do i reference it? Im trying to recall that tag on a double click event of the listitem at runtime. I was hoping it would be something like this (stub)
MessageBox.Show(lsvItems.SelectedIt开发者_StackOverflowem.Tag);
how do i get at this?
Make sure there is at least one item selected and then you can do
MessageBox.Show(lstView.SelectedItems[0].Tag.ToString());
If you have a defined entity (for eg. Person instance) added to Tag then you could do
Person p = (Person) lstView.SelectedItems[0].Tag
and access the instance's properties
MessageBox.Show(p.Name);
Assuming one item is selected:
MessageBox.Show(listView1.SelectedItems[0].Tag.ToString());
精彩评论