将对象分配给标记属性 [英] Assigning Object to Tag property
本文介绍了将对象分配给标记属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的代码..
class ABC
{
public string 姓名,电话;
public static IEnumerable< ABC> GetList()
{
List< ABC> foo = new 列表< ABC>();
// 这里有一些COED
return foo;
}
}
A类
{
私有 void GetList()
{
IEnumerable< ABC> abc = ABC.GetList();
foreach (ABC newitem in abc)
{
ListViewItem li = new ListViewItem();
li.Text = newitem.Name;
li.Tag = newitem; // <<<<<<<<<<<<< <这可能吗 ???
ListView1.Items.Add(li);
}
}
}
我想知道如果我可以将一个对象分配给ListViewItem的Tag属性??
为什么它可以在外面访问,因为该对象位于一个函数内?
它会导致任何问题在未来 ??记忆等.... :(请Helpp :(
解决方案
是的,你可以。
这是Tag属性的主要用途之一。
请参阅MSDN的 system.windows.forms.listviewitem.tag(v = vs.110).aspx [ ^ ]文章,他们也是一个用法示例。
祝你好运,
Edo
分配ListView的对象到标签属性 [ ^ ]同样的问题,同一作者。 ..
I have a code like this..
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 :(
解决方案
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
Assigning Object to Tag property of ListView[^] Same question, same author...
这篇关于将对象分配给标记属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文