Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Get all parents of a Treeviewitem for a file browser
1 replies. Latest Post by xkrja on June 27, 2009.
(0)
xkrja
Member
67 points
136 Posts
06-26-2009 6:09 PM |
I went through Justin's tutorial about the TreeViewControl found here:
http://silverlight.net/blogs/justinangel/archive/2008/11/18/silverlight-toolkit-treeview-treeviewitem-amp-hierarchaldatatemplate.aspx
I thought that I should use a modified version of the last part in the tutorial so that I can use the treeview for a file browser on the server. The thing is I need to get the file path whenever I click on a TreeViewItem (which will be a directory or file) in the treeview and to do that I must get all the parents of the node I just clicked, right? So, how can I loop through all parents of that treeViewItem so I can get the path?
If there is a better way to do this I'm open for suggestions.
Thanks!
06-27-2009 4:17 AM |
I solved it myself. I made a recursive method that looked like this:
private void GetTreeViewHeader(TreeViewItem expanded) { TreeViewItem parent; if (expanded.Parent is TreeViewItem) { parent = (TreeViewItem)expanded.Parent; invertedPath += parent.Header.ToString() + "#"; GetTreeViewHeader(parent); } }