如何在C#的Listview中显示这些项目? [英] How can i display these items in Listview in C#?

查看:53
本文介绍了如何在C#的Listview中显示这些项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个包含70个项目的ArrayList.我想在Listview中显示这些项目.因此,我使用了以下代码.
但是,当我按下按钮时,程序将仅显示arrayList中的前七个项目.其余项目未显示在列表视图中.
如何解决此问题?

干杯,

------------ BEGIN -------------------

Hi all,

I have an ArrayList that contains 70 items. I would like to display these items in Listview. Therefore, I used the following code.
However, When I press the button, program will only display the first seven items in the arrayList. The rest of items are not being displayed in listview.
How can I fix this problem ?

Cheers,

------------BEGIN---------------

private void btn_CreateReport_Click(object sender, EventArgs e)
{
     lstview.Items.Clear();
     int counterOfArraylist = mcarraylist.Count;
     string[] str = new string[counterOfArraylist];
     for (int i = 0; i < str.Length; i++)
     {

         str[i] = mcarraylist[i].ToString();

      }
      lstview.Items.Add(new ListViewItem(str));
}


------------ END ---------------

[修改:固定的前置标签]


------------END---------------

[Modified: fixed pre tags]

推荐答案

为什么只添加一项,将所有这些字符串串联在一起?
为什么根本不需要str,为什么不要做:
why are you adding only one item, a concatenation of all those strings?
why do you need str at all, why not just do:
lstview.Items.Add(mcarrayList[i].ToString());


在for循环中?

:)


inside the for loop?

:)





Hi,


April Zoom写道:
April Zoom wrote:

lstview.Items.Add(new ListViewItem(str));

lstview.Items.Add(new ListViewItem(str));



在这一行中,当您将字符串数组传递给ListViewItem构造函数时,实际上是在创建一个包含多个子项目"的单个项目.然后,将单个ListViewItem添加到您的ListView中.不应在ListView中看到更多的一个"项目.

您的Items.Add应该在循环内,每个字符串值都应该传递给ListViewItem构造函数.



In this line when you pass the array of string to ListViewItem contructor, you are actually creating a single listitem with multiple ''subitem'' in it. Then that single ListViewItem is added to your ListView. Should not see more that ''one'' item to ListView.

Your Items.Add should be inside the loop each string value should be passed to ListViewItem contructor.


这篇关于如何在C#的Listview中显示这些项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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