如何添加到列表视图项的特定列? [英] How do I add to a specific column in Listview item?

查看:109
本文介绍了如何添加到列表视图项的特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个列表视图和列数在运行时确定的。我一直在阅读网页上的文字全约的ListView(和我还在),但我想知道如何将项目添加到我觉得有点像在ListView中一个特定列:

I create a listview and the number of columns are determined at runtime. I have been reading texts on the web all over about listview( and I still am) but I wish to know how to add items to a specific column in listview I thought something like:

m_listview.Items.Add("1850").SubItems.Add("yes");

将工作假设1850这是列文将目标列。

would work assuming the "1850" which is the text of the column would be the target column.

推荐答案

ListViewItems不知道你的ListView列。

ListViewItems aren't aware of your ListView columns.

为了直接引用列,首先需要的所有列添加到ListViewItem的。

In order to directly reference the column, you first need to add all the columns to the ListViewItem.

所以......让我们说你的ListView有三列A,B和C; 的code这下位只会将数据添加到列A:

So... lets say your ListView has three columns A, B and C; This next bit of code will only add data to column A:

ListViewItem item = new ListViewItem();
item.text = "Column A";

m_listView.Items.Add(item);

要得到它的文本添加到C柱,以及,我们首先需要告诉它有一个B列...

To get it to add text to column C as well, we first need to tell it it has a column B...

ListViewItem item = new ListViewItem();
item.text = "Column A";
item.SubItems.Add("");
item.SubItems.Add("Column C");

m_listView.Items.Add(item);

所以,现在我们将有列A,B和C在ListViewItem,和文字出现在A和C列,但不能对B。

So now we'll have columns A, B and C in the ListViewItem, and text appearing in the A and C columns, but not the B.

终于...现在我们已经告诉了它有三列,我们可以做任何我们喜欢那些特定的列...

Finally... now that we HAVE told it it has three columns, we can do whatever we like to those specific columns...

ListViewItem item = new ListViewItem();
item.text = "Column A";
item.SubItems.Add("");
item.SubItems.Add("Column C");

m_listView.Items.Add(item);

m_listView.Items[0].SubItems[2].Text  = "change text of column C";
m_listView.Items[0].SubItems[1].Text  = "change text of column B";
m_listView.Items[0].SubItems[0].Text  = "change text of column A";

希望帮助!

这篇关于如何添加到列表视图项的特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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