Click here to Skip to main content
15,922,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am using TreeView and TreeViewItem in WPF and get selected item with this code ::
C#
var selecteditem = (TreeViewItem)(TreeView
                             .ItemContainerGenerator
                             .ContainerFromItem(TreeView.SelectedItem));

But My problem is that if i select a SubItem an extension say :
Object reference not set to an instance of an object.
Please give me a solution that i can get SubItem.
Thanks...
Posted

visit here.....



A Simple WPF Explorer Tree[^]
 
Share this answer
 
Comments
ali sedighian 9-Sep-13 9:30am    
yhanks for help!it was very helpfull.
[no name] 9-Sep-13 9:38am    
ok...your welcome dear...
Why not just
C#
var selecteditem = TreeView.SelectedItem;
 
Share this answer
 
Comments
ali sedighian 9-Sep-13 8:50am    
Because With this i can't access header or tag of selected item
ali sedighian 9-Sep-13 9:29am    
hey it was help but i use this:
TreeViewItem temp = ((TreeViewItem)tree.SelectedItem);

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