简体   繁体   中英

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>

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

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

Try:

ListViewItem lvi = new ListViewItem();

MyListView.Items.Add(lvi);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM