Jump to content

How can i display these items in Listview in C#?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
april.zoom

april.zoom

    Newbie

  • Members
  • Pip
  • 1 posts
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---------------

#2
veda87

veda87

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
I guess you have to use the lstview.Items.Add inside the for loop
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[i])); 
}

}
Try this, Hopefully, it might work...