CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Posts
    144

    Display List items in ListView

    I'm having major brain-fart.

    On my form I have a List of a custom class. It's a very simple class that just holds values for multiple properties. All I want to do is display the value of 2 of these properties for each class in a ListView. I can easily do it in a single column, like this:

    Code:
    private void UpdateCreatureList()
            {
                lvwCreatures.Items.Clear();
                foreach (Creature item in Creatures)
                {
                    lvwCreatures.Items.Add(item.CreatureName + ": " + item.Miniature);
                }
            }
    Creatures is the List<Creature> object.

    What I want to do is change the ListView so it has 2 columns: Creature & Miniature. Then I want to populate each column with its respective property value from the List.
    Code:
    if (Issue.Resolved)
    {
         ThreadTools.Click();
         MarkThreadResolved();
    }

  2. #2
    Join Date
    Jun 2008
    Posts
    154

    Re: Display List items in ListView

    I don't see anything wrong with what your doing there....

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Display List items in ListView

    Are you setting your list view to the correct style, i.e. Detail or is it Report? Haven't worked much with Listview in .Net but should be something like that, additional columns are subitems of the item in question.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Display List items in ListView

    Details would be the best View here, then you could do something like :

    Code:
            private void UpdateCreatureList()
            {
                lvwCreatures.Items.Clear();
                foreach (Creature item in Creatures)
                {
                    ListViewItem lvItem1 = new ListViewItem(item.CreatureName,0);
    
                    lvItem1.SubItems.Add(item.Miniature);
                }
            }

  5. #5
    Join Date
    Dec 2008
    Posts
    144

    Re: Display List items in ListView

    I wasn't in Details view and I added in the SubItems- that got everything working.

    Thanks,
    Code:
    if (Issue.Resolved)
    {
         ThreadTools.Click();
         MarkThreadResolved();
    }

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