Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello sir
when m using the code,its showing Object reference not set to an instance of an object.actually m using treeview which showing data from the xml.
Posted
Updated 4-Nov-11 1:05am
v3

1 solution

You are retrieving the SelectedItem property from 'treeviewitem' instead of the TreeView itself. I'm surprised this doesn't throw a compile error.

Try this:
XML
private void treeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
    TreeViewItem theSelectedItem = treeView1.SelectedItem as TreeViewItem;

    MessageBox.Show(theSelectedItem.ToString());
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900