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.
Re: Display List items in ListView
I don't see anything wrong with what your doing there....
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.
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);
}
}
Re: Display List items in ListView
I wasn't in Details view and I added in the SubItems- that got everything working.
Thanks,