Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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---------------
C#
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---------------

[Modified: fixed pre tags]
Posted
Updated 7-Apr-10 6:19am
v2

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());

inside the for loop?

:)
 
Share this answer
 
Hi,


April Zoom wrote:
lstview.Items.Add(new ListViewItem(str));


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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900