Paul Michaels
Paul Michaels

Reputation: 16685

Adding a list view item to a listview in WPF

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">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Column1" Width="300" />
                <GridViewColumn Header="Column2" Width="100" />                    
            </GridView>
        </ListView.View>
    </ListView>

Upvotes: 0

Views: 2087

Answers (2)

Christian
Christian

Reputation: 4375

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

Try:

ListViewItem lvi = new ListViewItem();

MyListView.Items.Add(lvi);

Upvotes: 1

Ian
Ian

Reputation: 34489

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

Upvotes: 2

Related Questions