Click here to Skip to main content
15,890,932 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to get selected index of treenode in C#.

I have Treeview, I stored Treeview Nodes values into database. Now i want to add nodes in runtime.. for that i want to get the selected index of selected tree node..

Id | Name | ParentNode
1 Root 0
2 Leaf 1

I want to store the Selected index value to parentnode column...
Posted
Updated 11-Nov-11 18:23pm
v3

1 solution

you may try this but, for more specific answers please elaborate your question possibly with some examples.
In this example i have used an xml file to populate the tree view and then getting the selected value.
C#
private void _treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
       {
           if ((((System.Windows.Controls.ItemsControl)(sender)).Items).Count > 0)
           {
               string CategoryName = (((System.Xml.XmlElement)(_treeView.SelectedItem))).Attributes[0].Value;
               string Name = (((System.Xml.XmlElement)(_treeView.SelectedItem))).Attributes[1].Value;
               string Imageref = (((System.Xml.XmlElement)(_treeView.SelectedItem))).Attributes[2].Value;
}
}


probably you may get some hint from this example..
 
Share this answer
 
Comments
Member 8393790 12-Nov-11 0:18am    
Thanks Tiwari for reply..

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