开发者

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开发者_Go百科,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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜