Tag Replacement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am using List View control to add few records(listview items) . I want to associate some data to each of the list view item or record that I add. It is very easy to do in normal C# by using Tag method. But unluckily Tag method is not supported in Compact Framework. Is there any replacement for the Tag method or is there any work around to do so

Please help
Thanks a lot

Amit Patankar
 
Use a ListViewItem that has the "tag" you want as part of it's class. The
items can be any object.

-Chris


Amit Patankar said:
Hi,

I am using List View control to add few records(listview items) . I want
to associate some data to each of the list view item or record that I add.
It is very easy to do in normal C# by using Tag method. But unluckily Tag
method is not supported in Compact Framework. Is there any replacement for
the Tag method or is there any work around to do so?
 
Hi Chris

Can you please elaborate more on this? May be with an example. Also how can I retrieve any Tagged info after I get the item ListItem Click event

Thanks a ton Chris

Amit Patanka

----- Chris Tacke, eMVP wrote: ----

Use a ListViewItem that has the "tag" you want as part of it's class. Th
items can be any object

-Chri


Amit Patankar said:
to associate some data to each of the list view item or record that I add
It is very easy to do in normal C# by using Tag method. But unluckily Ta
method is not supported in Compact Framework. Is there any replacement fo
the Tag method or is there any work around to do so
 
This is untested, but should give you the idea:

class MyTagItem : ListViewItem
{
private string m_tag;

public MyTagItem(string item, string tag) : base(item)
{
m_tag = tag;
}

public string Tag
{
get { return m_tag; }
set { m_tag = value; }
}
}

listView1.Items.Add(new MyTagItem("Item Text 1", "Item Tag 1"));
listView1.Items.Add(new MyTagItem("Item Text 2", "Item Tag 2"));
listView1.Items.Add(new MyTagItem("Item Text 3", "Item Tag 3"));
listView1.Click += new EventHandler(listView1_Click);

private void listView1_Click(object sender, EventArgs e)
{
MessageBox.Show(((MyTagItem)listView1.SelectedItems[0]).Tag);
}


P.S. If it works, please let me know and I'll add it to the OpenNETCF Wiki.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Principal Partner
OpenNETCF Consulting
www.OpenNETCF.com



Amit Patankar said:
Hi Chris,

Can you please elaborate more on this? May be with an example. Also how
can I retrieve any Tagged info after I get the item ListItem Click event?
 
We actually had it in the forums for a while:
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=676

--
Alex Feinman
---
Visit http://www.opennetcf.org
Chris Tacke said:
This is untested, but should give you the idea:

class MyTagItem : ListViewItem
{
private string m_tag;

public MyTagItem(string item, string tag) : base(item)
{
m_tag = tag;
}

public string Tag
{
get { return m_tag; }
set { m_tag = value; }
}
}

listView1.Items.Add(new MyTagItem("Item Text 1", "Item Tag 1"));
listView1.Items.Add(new MyTagItem("Item Text 2", "Item Tag 2"));
listView1.Items.Add(new MyTagItem("Item Text 3", "Item Tag 3"));
listView1.Click += new EventHandler(listView1_Click);

private void listView1_Click(object sender, EventArgs e)
{
MessageBox.Show(((MyTagItem)listView1.SelectedItems[0]).Tag);
}


P.S. If it works, please let me know and I'll add it to the OpenNETCF Wiki.

--
Chris Tacke, eMVP
Co-Founder and Advisory Board Member
www.OpenNETCF.org
---
Principal Partner
OpenNETCF Consulting
www.OpenNETCF.com



Amit Patankar said:
Hi Chris,

Can you please elaborate more on this? May be with an example. Also how
can I retrieve any Tagged info after I get the item ListItem Click event?
Thanks a ton Chris.

Amit Patankar

----- Chris Tacke, eMVP wrote: -----

Use a ListViewItem that has the "tag" you want as part of it's
class.
The
items can be any object.

-Chris
..
I want
to associate some data to each of the list view item or record that
I
add.
It is very easy to do in normal C# by using Tag method. But
unluckily
Tag
method is not supported in Compact Framework. Is there any replacement for
the Tag method or is there any work around to do so?
 
Back
Top