Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

URGENT Need help with ListView Tag item

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.
  • 2
1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
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++)
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)
            this.cat = sCat;
            this.dog = 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 = pit.cat;
            txtDog.Text = pit.dog;
            txtPetAge.Text = pit.petAge;
            txtPetName.Text = pit.petName;

this is a very professional solution.
plz inform me about ur opion

thanks for grade A
NewMom2BrandonAuthor Commented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now