ListViewItem in WPF ListView
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]);
精彩评论