Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another way you can preserve the scroll position without external functions is using the TopNode property of the tree...</p> <p>TopNode gets or sets the first fully-visible tree node in the tree view control.</p> <p>If you just want to expand a node and have it preserve the top node:</p> <pre><code>TreeNode topNode = m_Tree.TopNode; treenode.Expand(); m_Tree.TopNode = topNode; </code></pre> <p>Otherwise, if you are rebuilding a tree (such as refreshing a file structure), you can use the following method...</p> <p>Before Clearing the tree, store the full path to the top node:</p> <pre><code>string topNodePath = null; TreeNode topNode = null; if (m_Tree.TopNode != null) { topNodePath = m_Tree.TopNode.FullPath; } m_Tree.Clear(); </code></pre> <p>After adding a nodes, check its FullPath against the topNodePath:</p> <pre><code>nodes.Add(node) if ((topNodePath != null) &amp;&amp; (node.FullPath == topNodePath)) { topNode = node; } </code></pre> <p>After adding all nodes, update the tree's TopNode property:</p> <pre><code>if (topNode != null) { m_Tree.TopNode = topNode; } </code></pre> <p>I use a similar technique for selected and expanded nodes. SelectedNode works almost exactly as TopNode shown above. For expanded nodes I use a recursive function to loop through the child nodes and add the path of expanded nodes to a list. Then expands them based on their path after the children have been added.</p> <p>Of course, if you have a lot of sibling nodes with the same name, this might not work as well :-)</p>
    singulars
    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. VO
      singulars
      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