添加后看不到任何项目

问题描述 投票:0回答:1

将列表中的项目添加到其中后,我的列表视图不显示任何内容。为什么? 我的列表不是空的我的程序进入这个循环。 那么将项目添加到列表视图中的代码是错误的吗?因为我看到很多聊天室,而且还有微软,我可以像这样添加它们。

enter image description here

我也尝试了这个代码:listView1.Items.Add(new ListViewItem { ImageKey = "Person", Text = database1[counter1].name });

这里是我的imglist的图片,列表在thelistview中选择:enter image description here

enter image description here

c# listview listviewitem
1个回答
0
投票

如果没有列,则无法添加项目,或者您可以,但它们不会显示。您是否在listView中添加了一些列?

//Adds needed columns
this.listView1.Columns.Add("<column_name>", 50);

如果您有一列,则可以通过以下方式添加项目:

ListViewItem itm = new ListViewItem("my_item");
listView1.Items.Add(itm);

如果您有多个列而不是字符串,则可以使用字符串数组,其中数组大小等于列数。

string[] items = new string[listView1.Columns.Count];

在你的代码中也尝试这个,在我的代码中只适用于:

this.listView1.View = View.Details;
© www.soinside.com 2019 - 2024. All rights reserved.