|
-
April 7th, 2010, 08:27 AM
#1
How to display ArrayList items in Listview?
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. 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---------------
-
April 7th, 2010, 10:00 AM
#2
Re: How to display ArrayList items in Listview?
First of all you can use code tags instead of 'BEGIN' and 'END'. Just surround the code with [code] [ /code].
Have you tried adding the list items at the same time as you populate the array of strings ('str')? Or have you thought of setting 'str' as the data source for the list view?
-
April 7th, 2010, 10:03 AM
#3
Re: How to display ArrayList items in Listview?
You have this:
 Originally Posted by aprilzoom
for (int i = 0; i < str.Length; i++)
Try this:
Code:
for (int i = 0; i < counterOfArraylist; i++)
-------------------------------------------------------------------------------------
btw the best way to display code is to put code brackets around it.
example
[ CODE ]
code code code blah blah
[ /CODE ] (just remove the spaces in the brackets and it will look like this:
Code:
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));
}
- It's a long way to the top if you want to rock n' roll - AC/DC
Check out my band and support the music:
www.blueruinmusic.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|