URGENT Need help with ListView Tag item

Posted on 2006-05-15
Last Modified: 2009-12-16
I have a tag assigned to each item added into a listview.

It looks like this
item.Tag = sCat + ", " + sDog + ", " + sBreed + ", " + sPetName + ", " + sPetAge;

What I need to pull the first item from the listview and populate 5 text boxes with the information in the tag. For example Cat would go in 1 box, dog in another and so on.

Then if the listview selected item changes...I would need to update the fields with the new tag information.

The reason I used Tags was becasue I couldn't think of another way to have the information hidden from the main screen. So I just used the tag for each line.

Does anyone have any code examples on how I could do this. Or a better way of doing this.
Question by:NewMom2Brandon
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    I would get rid of the space after your comma...then use code like this:

                item.Tag = sCat + "," + sDog + "," + sBreed + "," + sPetName + "," + sPetAge;

                String[] values = item.Tag.ToString().Split(",".ToCharArray());
                for (int i = 0; i <= values.GetUpperBound(0); i++)
    LVL 5

    Accepted Solution

    u can use oop
    the tag property take object so put pit object like this in the tag property

    class Pit
            public Pit(string sCat, string sDog, string sBreed, string sPetName, string sPetAge)
       = sCat;
       = sDog;
                this.bread = sBreed;
                this.petName = sPetName;
                this.petage = sPetAge;

            public string cat;
            public string dog;
            public string bread;
            public string petName;
            public string petage;

    and on ItemSelectionChanged use the pit object from the tag prperty

            private void lstvwPits_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
                ListViewItem lvi = e.Item;
                Pit pit = (Pit)lvi.Tag;
                txtBreed.Text = pit.bread;
                txtCat.Text =;
                txtDog.Text =;
                txtPetAge.Text = pit.petAge;
                txtPetName.Text = pit.petName;

    this is a very professional solution.
    LVL 5

    Expert Comment

    plz inform me about ur opion

    thanks for grade A
    LVL 2

    Author Comment

    I think it is a very professional solution. Concidering I need to access these values in mulitiple places making it public is a better than using the same function in mulitple places.

    This was the way I would have gone if several other factors had not needed to change in my project. Instead I went the direction of creating a hashtable and using that to filter out the view instead of using the tags.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now