TreeView.SelectedValue Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the value of the property that is the specified by SelectedValuePath for the SelectedItem.
public:
property System::Object ^ SelectedValue { System::Object ^ get(); };
[System.ComponentModel.Bindable(true)]
public object SelectedValue { get; }
[<System.ComponentModel.Bindable(true)>]
member this.SelectedValue : obj
Public ReadOnly Property SelectedValue As Object
Property Value
The value of the property that is specified by the SelectedValuePath for the SelectedItem, or null
if no item is selected. The default value is null
.
- Attributes
Examples
The following example shows a TreeView that uses a HierarchicalDataTemplate to display the EmployeeName
and EmployeeWorkDay
properties of an Employee
and sets the SelectedValue property to the EmployeeNumber
. When you select an EmployeeName
in the TreeView, the SelectedValue is set to the EmployeeNumber
.
<TreeView ItemsSource="{Binding Source={StaticResource myEmployeeData},
XPath=EmployeeInfo}"
Name="myTreeView"
SelectedValuePath="EmployeeNumber"
/>
<TextBlock Margin="10">SelectedValuePath: </TextBlock>
<TextBlock Margin="10,0,0,0"
Text="{Binding ElementName=myTreeView,
Path=SelectedValuePath}"
Foreground="Blue"/>
<TextBlock Margin="10">SelectedValue: </TextBlock>
<TextBlock Margin="10,0,0,0"
Text="{Binding ElementName=myTreeView,
Path=SelectedValue}"
Foreground="Blue"/>
Remarks
The SelectedValuePath property specifies the path to the property that is used to determine the value of the SelectedValue property. For example, assume that a TreeView is bound to a collection of objects of type Employee
, which has two properties called EmployeeName
and EmployeeNumber
. You can use a HierarchicalDataTemplate to display the value of EmployeeName
in the TreeView and set SelectedValuePath to "EmployeeNumber"
to have SelectedValue return the value of EmployeeNumber
.
The SelectedValue property is a read-only property. To change the value of a selected item in a TreeView, use the SelectedItem property to access the TreeViewItem.
Dependency Property Information
Identifier field | SelectedValueProperty |
Metadata properties set to true |
None |
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기