How can I get the current item in one of the Item controls?
WPF has several items controls such as ListView, ListBox, and ComboBox. You can typically use the SelectedItem property to determine the currently selected item.
Alternately, when you bind a collection to an items control, a data view is created behind the scenes. This data view tracks the current item and supports sorting, filtering, and grouping. Since these features are independent of the collection, you can bind the same collection two multiple lists but filter, sort, and group them differently.
Depending on the interface implemented by your collection, you get a different type of view object:
- If the collection implements IBindingList (as MM .NET collections do) a BindingListCollectionView is created
- If the collection implements IList, a ListCollectionView is created
- If the collection implements IEnumerable, a CollectionView is created
To get a view object, you must call the CollectionViewSource.GetDefaultView() method passing a reference to the bound collection (and you must cast the result to the correct type). For example:
BindingListCollectionView view =
(BindingListCollectionView)CollectionViewSource.GetDefaultView(lstList.ItemsSource);
NOTE: In order for the CurrentItem property of the view to reflect the currently selected item, the associated item control must have its IsSynchronizedWithCurrentItem property set to true.
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 10/23/10
Comment or report problem with topic
