Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a code like this..

C#
class ABC
{
   public string Name, Phone; 

   public static IEnumerable<ABC> GetList()
   {
      List<ABC> foo = new List<ABC>();

      //Some COde here
      return foo; 
   }
}

Class A
{
   private void GetList()
   {
      IEnumerable<ABC> abc = ABC.GetList();
      foreach (ABC newitem in abc)
      {
         ListViewItem li = new ListViewItem();
         li.Text = newitem.Name;
         li.Tag = newitem; //<<<<<<<<<<<<< Is this Possible ??? 
         ListView1.Items.Add(li);
      }
   }
}



I want to know If I can assign an object to the Tag Property of ListViewItem ??
How come it be accessible outside since the object resides inside a function ??
Will it cause any problems in future ?? Memory and so.... :( Please Helpp :(
Posted
Updated 2-Jul-13 23:18pm
v2

Yes, you can.

This is one of the major uses of the Tag property.
See MSDN's system.windows.forms.listviewitem.tag(v=vs.110).aspx[^] article, they also a usage example there.

Good luck,
Edo
 
Share this answer
 
Assigning Object to Tag property of ListView[^] Same question, same author...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900