Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are some unclear moments in your code:</p> <ol> <li>Do you want to explicitly restrict path depth (e.g. show paths up to 3d level only)</li> <li>What is ListWithPaths? Can two paths have a common node?</li> </ol> <p>To show a single path with restriction (depth) the code could be</p> <pre><code>private void PopulateTree(String path, TreeNode parent, int depth) { if (depth == 0) // &lt;- Artificial criterium return; if (String.IsNullOrEmpty(path)) return; int index = path.IndexOf(Path.DirectorySeparatorChar); String directoryName = (index &lt; 0) ? path : path.Substring(0, index); String otherName = (index &lt; 0) ? null : path.Substring(index + 1); TreeNode childNode = parent.Nodes.Add(directoryName); PopulateTree(otherName, childNode, depth - 1); } </code></pre> <p>In order to load a collection of paths without any restriction <em>with possible common nodes</em> you can use something like this:</p> <pre><code>private void PopulateTree(String path, TreeView view, TreeNode parent) { if (String.IsNullOrEmpty(path)) return; int index = path.IndexOf(Path.DirectorySeparatorChar); String directoryName = (index &lt; 0) ? path : path.Substring(0, index); String otherName = (index &lt; 0) ? null : path.Substring(index + 1); TreeNode childNode = null; TreeNodeCollection nodes = (parent == null) ? view.Nodes : parent.Nodes; foreach (TreeNode node in nodes) if (String.Equals(node.Name, directoryName)) { childNode = node; break; } if (childNode == null) childNode = nodes.Add(directoryName); PopulateTree(otherName, view, childNode); } private void PopulateTree(IEnumerable&lt;String&gt; paths, TreeView view) { view.BeginUpdate(); try { foreach (String path in paths) PopulateTree(path, view, null); } finally { view.EndUpdate(); } } ... PopulateTree(ListWithPaths, MyTreeView) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload