ListViewItem的 [英] ListViewItem

查看:63
本文介绍了ListViewItem的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ListView来显示名称列表,并希望在列表中存储

id但不可见。


我试图通过使用ListViewItem并设置

文本和标签属性来实现此目的。问题是当我将ListViewItem添加到

ListView时,我得到以下内容


ListViewItem:{Test1}

ListViewItem:{ Test2}

ListViewItem:{Test3}


其中Test1,Test2和Test3是我分配给Text属性的名称。

我在这里做错了什么?


谢谢


Gav

I am trying to have a ListView to dispay a list of names and want to have an
id stored within the list but not visable.

I have tried to go about doing this by using the ListViewItem and setting
the Text and Tag properties. Problem is when I add the ListViewItem to the
ListView I get the following

ListViewItem: {Test1}
ListViewItem: {Test2}
ListViewItem: {Test3}

Where Test1, Test2 and Test3 are the names I assigned to the Text property.

What amI doing wrong here?

thanks

Gav

推荐答案

听起来你没有做错任何事。根据你的描述,

你做了以下事情;


ListViewItem m = new ListViewItem();

m.Text =" ; Test1";

m.Tag = new< Class(ID)> ;;

ListView.Items.Add(m);


等等。


你不想要Test1吗?在ListView中显示?如果没有,那么将Text属性设置为

即可显示。或者我想念

什么?


Dom

12月14日上午11点12分,Gav < g ... @nospam.comwrote:
It doesn''t sound like you did anything wrong. From your description,
you did the following;

ListViewItem m = new ListViewItem();
m.Text = "Test1";
m.Tag = new <Class (ID)>;
ListView.Items.Add (m);

And so on.

Did you not want "Test1" to show in the ListView? If not, then set
the Text property to whatever you want to show. Or did I miss
something?

Dom
On Dec 14, 11:12 am, "Gav" <g...@nospam.comwrote:

我正在尝试使用ListView来显示名称列表并希望有一个

id存储在列表中但不可见。


我试图通过使用ListViewItem来设置

文本和标签属性。问题是当我将ListViewItem添加到

ListView时,我得到以下内容


ListViewItem:{Test1}

ListViewItem:{ Test2}

ListViewItem:{Test3}


其中Test1,Test2和Test3是我分配给Text属性的名称。

我在这里做错了什么?


谢谢


Gav
I am trying to have a ListView to dispay a list of names and want to have an
id stored within the list but not visable.

I have tried to go about doing this by using the ListViewItem and setting
the Text and Tag properties. Problem is when I add the ListViewItem to the
ListView I get the following

ListViewItem: {Test1}
ListViewItem: {Test2}
ListViewItem: {Test3}

Where Test1, Test2 and Test3 are the names I assigned to the Text property.

What amI doing wrong here?

thanks

Gav




" Dom" < do ******** @ gmail.comwrote in message

news:10 ********************** ************ @ s19g2000 prg.googlegroups.com ...

"Dom" <do********@gmail.comwrote in message
news:10**********************************@s19g2000 prg.googlegroups.com...

听起来你没有做错任何事。根据你的描述,

你做了以下事情;


ListViewItem m = new ListViewItem();

m.Text =" ; Test1";

m.Tag = new< Class(ID)> ;;

ListView.Items.Add(m);


等等。


你不想要Test1吗?在ListView中显示?如果没有,那么将Text属性设置为

即可显示。或者我错过了

的东西?


Dom
It doesn''t sound like you did anything wrong. From your description,
you did the following;

ListViewItem m = new ListViewItem();
m.Text = "Test1";
m.Tag = new <Class (ID)>;
ListView.Items.Add (m);

And so on.

Did you not want "Test1" to show in the ListView? If not, then set
the Text property to whatever you want to show. Or did I miss
something?

Dom



是的,这就是我在做什么,请参阅下面的代码。记录1和2都是字符串。


lvi = new ListViewItem();


lvi.Text = record [1];


lvi.Tag = record [0];


this.lbx_Members.Items.Add(lvi);


问题是当项目在ListView中显示时,它显示为

" ListViewItem:{Test1}"而不是Test1。


Gav

Yes that is what I am doing, see code below. Record 1&2 are both strings.

lvi = new ListViewItem();

lvi.Text = record[1];

lvi.Tag = record[0];

this.lbx_Members.Items.Add(lvi);

The problem is when the item is displayed in the ListView it appears as
"ListViewItem: {Test1}" rather than "Test1".

Gav


On Sun,2007年12月16日02:24:16 -0800,Gav < ga*@nospam.comwrote:
On Sun, 16 Dec 2007 02:24:16 -0800, Gav <ga*@nospam.comwrote:

[...]

lvi = new ListViewItem();

lvi.Text = record [1];

lvi.Tag = record [0];

this.lbx_Members.Items.Add(lvi);


问题是当项目在ListView中显示时,它显示为

" ListViewItem:{Test1}"而不是Test1。
[...]
lvi = new ListViewItem();
lvi.Text = record[1];
lvi.Tag = record[0];
this.lbx_Members.Items.Add(lvi);

The problem is when the item is displayed in the ListView it appears as
"ListViewItem: {Test1}" rather than "Test1".



您的问题是一个很好的例子,说明为什么发布完整的

代码示例非常重要。你真的没有为任何人提供足够的细节

实际回答这个问题,因为没有显示你的变量的声明或

初始化。


说:基于你给控件的名称,lbx_Members,似乎

可能是控件不是ListView,而是ListBox。如果

这是真的,那么ListViewItem当然不会作为列表工作

元素。除了

ListViewItem.ToString()方法返回的内容之外,ListBox对此一无所知。


如果没有回答你的话问题,请发一个_complete_问题,

包括一个简洁但完整的代码示例,可以可靠地再现你的问题。


Pete

Your question is a great example of why it''s so important to post complete
code examples. You really have not provided enough details for anyone to
actually answer the question, because none of the declarations or
initialization of your variables is shown.

That said: based on the name you gave the control, "lbx_Members", it seems
likely that the control isn''t a ListView, but rather is a ListBox. If
that''s true, then of course the ListViewItem isn''t going to work as a list
element. ListBox doesn''t know anything about it, other than what the
ListViewItem.ToString() method returns.

If that doesn''t answer your question, please post a _complete_ question,
including a concise-but-complete example of code that reliably reproduces
your problem.

Pete


这篇关于ListViewItem的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆