CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2010
    Posts
    3

    Question 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---------------

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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?

  3. #3
    Join Date
    Feb 2009
    Posts
    112

    Re: How to display ArrayList items in Listview?

    You have this:

    Quote Originally Posted by aprilzoom View Post

    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
  •  





Click Here to Expand Forum to Full Width

Featured