SelectedItemChanged Event
Collapse the table of content
Expand the table of content

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>
  <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 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
Silverlight
Available since 3.0
Return to top
Show:
© 2016 Microsoft