Avatar of trevor1940
trevor1940
 asked on

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

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);

Open in new window

        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


         }
.NET ProgrammingC#

Avatar of undefined
Last Comment
trevor1940

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
AndyAinscow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
trevor1940

ASKER
Thanx Andy

I did have to cast the object
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23