开发者

ListViewItem in WPF ListView

开发者 https://www.devze.com 2022-12-31 04:15 出处:网络
I\'m attempting to get the ListViewItem object from the currently s开发者_运维百科elected row of a data bound ListView, like so:

I'm attempting to get the ListViewItem object from the currently s开发者_运维百科elected row of a data bound ListView, like so:

ListViewItem selectedItem = new ListViewItem();
selectedItem = (ListViewItem)listView1.Items[index];

what this does however, is returns the object type the ListView is bound to, in this instance, its a company class object for a database. What I would like it to return is the actual ListViewItem object itself (so that I can access its properties).

is there anyway to do this?

thanks


You have to use,

ListViewItem selectedListView = 
    (ListViewItem)listView1.ItemContainerGenerator.GetContainerForItem(
        listView1.Items[index]);
0

精彩评论

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