troubleshooting Question

C#:  Tagging an object to a listview item and retrieving  it

Avatar of trevor1940
trevor1940 asked on
.NET ProgrammingC#
2 Comments1 Solution76 ViewsLast Modified:
This page suggests the tag can be referenced  to any object

Can someone explain how to retrieve the properties of that object on selecting the listview item?

I get
Error      CS0029      Cannot implicitly convert type 'System.Windows.Forms.ListViewItem' to 'ClassName.Episode'      TVDB

sudo Code

//  build listview have accessed / created episode
............

                                    ListViewItem item = new ListViewItem();
                                    item.Text = fName;
                                    item.Tag = episode;
                                    item.SubItems.Add(newName);
                                    listView1.Items.Add(item);
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int i = listView1.SelectedIndices[0];
            string fName = listView1.Items[i].Text;

            Episode episode = listView1.Items[i];  // errors here


         }
ASKER CERTIFIED SOLUTION
AndyAinscow
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros