Skip to main content

Microsoft Silverlight

Answered Question Get all parents of a Treeviewitem for a file browserRSS Feed

(0)

xkrja
xkrja

Member

Member

67 points

136 Posts

Get all parents of a Treeviewitem for a file browser

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!

Please mark as answer if you found my post useful :-)

Thanks!

xkrja
xkrja

Member

Member

67 points

136 Posts

Answered Question

Re: Get all parents of a Treeviewitem for a file browser

 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);
            }
        }
  In this way I get the file path inverted but it's easy to invert it to the real format by just splitting the string and putting it together backwards.

Please mark as answer if you found my post useful :-)

Thanks!
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities