TreeView.SelectedItemChanged Event

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Occurs when the SelectedItem changes.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

Public Event SelectedItemChanged As RoutedPropertyChangedEventHandler(Of Object)

<object SelectedItemChanged="RoutedPropertyChangedEventHandler"/>

The following example shows how to specify an event handler for the SelectedItemChanged event.

<TreeView SelectedItemChanged="SelectionChanged">
  <TreeViewItem Header="Employee1" IsSelected="True">
    <TreeViewItem Header="Jesper"/>
    <TreeViewItem Header="Aaberg"/>
    <TreeViewItem Header="12345"/>
  </TreeViewItem>
  <TreeViewItem Header="Employee2">
    <TreeViewItem Header="Dominik"/>
    <TreeViewItem Header="Paiha"/>
    <TreeViewItem Header="98765"/>
  </TreeViewItem>
</TreeView>

The following example shows how to define the event handler.

Private Sub SelectionChanged(ByVal sender As Object, ByVal e As RoutedPropertyChangedEventArgs(Of Object))
	'Perform actions when SelectedItem changes
	MessageBox.Show((CType(e.NewValue, TreeViewItem)).Header.ToString())
End Sub

.NET Framework
Available since 3.0
Silverlight
Available since 3.0
Return to top
Show: