Andree1

Hello,
I have a problem with ListViewItem acces. I have a ListView/GridView in Xaml and with C# code behind. I want to be able to edit Items when I doubleClick to ListViewItem, but I don't know how to acces ListViewItem. If anyone knows pleas help,
Thanks Ondrej



Re: Windows Presentation Foundation (WPF) ListViewItem Acces

Anton__

ListView has Items property - clollection of all ListView contents.

but type of the items in the collection may be not ListViewItem type. ListViewItem is a container for the actual object...





Re: Windows Presentation Foundation (WPF) ListViewItem Acces

JDPeckham

you don't need access to the ListViewItem wrapper around your data objects to be able to edit them.

Here's what you probably want to do.

clone your selected object, send it and the clone to a page function, make your edits, if you hit save button on the page function you can send both of them to the return handler, otherwise don't even do the return handler just close the page func.

in the handler, take the old object, do a collectioninstance.indexof() on it, then removeat() then insert your new cloned and edited object at that index. Set that new object as selected.

keep in mind your listview itemssource must be an observablecollection and your business entity must implement inotifypropertychanged properly to see when items are added and removed.






Re: Windows Presentation Foundation (WPF) ListViewItem Acces

Yi-Lun Luo - MSFT

Hello, to get the underlying selected object, you can use:

object obj = list1.SelectedItem;

To get the actual ListViewItem, you can use:

ListViewItem item = (ListViewItem)list1.ItemContainerGenerator.ContainerFromItem(list1.SelectedItem);