I am assuming you're talking about WinForms
TreeView
?
In that case, try something like this;
private string GetPath(TreeNode node)
{
string path = "";
for (TreeNode iterator = node; iterator != null; iterator = iterator.Parent)
{
path = String.Format("{0}//{1}", iterator.Name, path);
}
return path;
}
private void FindPaths(TreeNodeCollection nodes,
IDictionary<TreeNode, string> paths)
{
foreach (TreeNode node in nodes)
{
if (node.Nodes.Count == 0)
paths[node] = GetPath(node);
else
FindPaths(node.Nodes, paths);
}
}
private void some_click_event(object sender, TreeViewEventArgs e)
{
IDictionary<TreeNode, string> paths = new Dictionary<TreeNode, string>();
FindPaths(treeView.Nodes, paths);
}
The
paths
dictionary will contain all the paths with their leaf node as key.
Hope this helps,
Fredrik