--- title: "How to: Use SelectedValue, SelectedValuePath, and SelectedItem" description: Learn how to use the SelectedValue and SelectedValuePath properties to specify a value for the SelectedItem of a Windows Presentation Foundation TreeView. ms.date: "03/30/2017" helpviewer_keywords: - "TreeView control [WPF], SelectedValue properties" - "Control class [WPF], SelectedItem properties" - "Control class [WPF], TreeView properties" - "Control class [WPF], SelectedValue properties" - "TreeView control [WPF], SelectedItem properties" - "SelectedValue [WPF], SelectedValuePath properties" - "TreeView control [WPF], SelectedValuePath properties" - "Control class [WPF], SelectedValuePath properties" - "SelectedValue [WPF], SelectedItem properties" ms.assetid: 2fc92ad4-f02c-4f89-bbe9-d4978a7af0db --- # How to: Use SelectedValue, SelectedValuePath, and SelectedItem This example shows how to use the and properties to specify a value for the of a . ## Example The property provides a way to specify a for the in a . The represents an object in the collection and the displays the value of a single property of the selected item. The property specifies the path to the property that is used to determine the value of the property. The examples in this topic illustrate this concept. The following example shows an that contains employee information. [!code-xaml[TreeViewSelectedValue#XMLDataProvider](~/samples/snippets/csharp/VS_Snippets_Wpf/TreeViewSelectedValue/CS/Window1.xaml#xmldataprovider)] The following example defines a that displays the `EmployeeName` and `EmployeeWorkDay` of the `Employee`. Note that the does not specify the `EmployeeNumber` as part of the template. [!code-xaml[TreeViewSelectedValue#HierarchicalDataTemplate](~/samples/snippets/csharp/VS_Snippets_Wpf/TreeViewSelectedValue/CS/Window1.xaml#hierarchicaldatatemplate)] The following example shows a that uses the previously defined and that sets the property to the `EmployeeNumber`. When you select an `EmployeeName` in the , the property returns the `EmployeeInfo` data item that corresponds to the selected `EmployeeName`. However, because the of this is set to `EmployeeNumber`, the is set to the `EmployeeNumber`. [!code-xaml[TreeViewSelectedValue#SelectedValuePath](~/samples/snippets/csharp/VS_Snippets_Wpf/TreeViewSelectedValue/CS/Window1.xaml#selectedvaluepath)] ## See also - - - [TreeView Overview](treeview-overview.md) - [How-to Topics](treeview-how-to-topics.md)