Take the 2-minute tour ×

I would have thought that I should be able to do something like this:

ListViewItem lvi = MyListView.Items.Add();

But MyListView.Items.Add() returns an integer. This seems to differ from the way it’s done in WinForms, can anyone point me in the right direction as to how this is achieved?

WPF Listview:

    <ListView Margin="12,108,12,12" Name="MyListView">
                <GridViewColumn Header="Column1" Width="300" />
                <GridViewColumn Header="Column2" Width="100" />                    
share|improve this question

2 Answers 2

up vote 1 down vote accepted

You want to add an item to the list, right?


ListViewItem lvi = new ListViewItem();

share|improve this answer
I would also recommend to bind data to your list view and then instead of adding a ListViewItem add the class you bound to the ListView. –  Christian Nov 18 '10 at 10:03
It could look like this: <ListView ItemsSource="{Binding Path=MyClass}"> <ListView.View> <GridView> <GridViewColumn DisplayMemberBinding="{Binding Path=MyProperty}" Header="Some header" /> </GridView> </ListView.View> </ListView> then in the code you can add an item of type MyClass. –  Christian Nov 18 '10 at 10:05

I'd go a bit further and checkout an online tutorial such as this or this. WPF controls often can't be treated in the same way as WinForm controls when it comes to handling data and binding...

share|improve this answer

Your Answer


