2

我有一个包含三列的 ListView,我想为每列添加字符串

这是代码

ListViewItem tempLV = new ListViewItem("first");
tempLV.SubItems.Add("second");
tempLV.SubItems.Add("third");
lv.Items.Add(tempLV);

和输出

在此处输入图像描述

如您所见,仅添加了第一列中的数据并将其包围ListViewItem:{}

ListView来自System.Windows.Controls, _

并且ListViewItem来自System.Windows.Forms,如果有帮助的话

使用 .NET 4.5

4

2 回答 2

-2

You are creating an instance of ListViewItem named "tempLV", and assigning that the "first" value. Then you are adding the next to ListViewItems AS SUBITEMS.

You need to create the ListViewItem like this:

var lvi = new ListViewItem();
lvi.SubItems.Add("first");
lvi.SubItems.Add("second");
lvi.SubItems.Add("third");

ListView lv = new ListView();
lv.Items.Add(lvi);
于 2013-08-02T20:28:21.660 回答
-3

If the requirement is to add three listview items, three instances of listview items should be made. SubItems won't work in this case

于 2013-08-03T02:48:05.890 回答