添加项目后,看不到任何项目

时间:2019-02-14 11:08:05

标签: c# listview listviewitem

将列表中的项目添加到列表后,我的列表视图什么也不显示。为什么?
我的列表不为空,我的程序进入此循环。
那么将代码添加到列表视图中的代码是否错误?因为我看到了很多聊天室,也从Microsoft看过,所以我可以像这样添加它们。

enter image description here

我也使用以下代码进行过尝试:listView1.Items.Add(new ListViewItem { ImageKey = "Person", Text = database1[counter1].name });

这里是我的imglist的图片,并且在listview中选择了该列表: enter image description here

enter image description here

1 个答案:

答案 0 :(得分: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;