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

    Problem with adding Item to a ListView

    Hey,
    i've Problems with adding Item's to my listView1 because its in a Static Function.

    Here how i try it:

    Code:
                    int[] myItems = new int[] 
         
                    {
                        GetName(i), // this one is a String
                        GetCount(i),
                        GetLevel(i),
                        GetMinBid(i),
                        GetMinIncrement(i),
                        GetBuyoutPrice(i),
                        GetBidAmmount(i),
                        GetOwner(i) // this one is a String
                    };
                    ListViewItem lvi = new ListViewItem(myItems);
                    listView1.Items.Add(lvi); //listView1 is red marked because its not Static!
    hope someone can help me with it.

  2. #2
    Join Date
    May 2005
    Location
    San Antonio Tx
    Posts
    44

    Re: Problem with adding Item to a ListView

    your question is a bit vague mate

    for starters the problem that i see here is that you are trying to pass int[] to the ListVieIitem constructor and you can't do that, ListVieIitem doesn't take int[] at least not on VS2005 which is the compiler im using but it does take string[] so you might want to start there.

    Second, Where do you get the idea that the the problem here is that listview1 is is not static?
    what compiler are you using that is giving you that message? and are you sure listview1 already exist?

    and lastly what are you trying to do here:
    Code:
    {
                        GetName(i), // this one is a String
                        GetCount(i),
                        GetLevel(i),
                        GetMinBid(i),
                        GetMinIncrement(i),
                        GetBuyoutPrice(i),
                        GetBidAmmount(i),
                        GetOwner(i) // this one is a String
    };
    looks like you are trying to populate the array using private functions all within a loop and if that is the case why are you trying to add strings to an int array?

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Problem with adding Item to a ListView

    Make the function not static, or pass the listView to it as an argument.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

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