The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TreeView.SelectedItemChanged Event


Occurs when the SelectedItem changes.

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

public event RoutedPropertyChangedEventHandler<object> SelectedItemChanged

<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 Header="Employee2">
    <TreeViewItem Header="Dominik"/>
    <TreeViewItem Header="Paiha"/>
    <TreeViewItem Header="98765"/>

The following example shows how to define the event handler.

private void SelectionChanged(object sender, RoutedPropertyChangedEventArgs<Object> e)
    //Perform actions when SelectedItem changes
    MessageBox.Show(((TreeViewItem) e.NewValue).Header.ToString());

.NET Framework
Available since 3.0
Available since 3.0
Return to top
© 2015 Microsoft