Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I assume that you are trying to select a particular node in your <code>TreeView</code>, whereas the code snippet that you posted above only sets focus to the <code>TreeView</code> control itself.</p> <p>To do this, you need to set the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.selectednode.aspx" rel="nofollow"><code>SelectedNode</code> property</a> of the <code>TreeView</code> control to the individual node item that you want to appear as selected. The specified node is automatically scrolled into view and all of its its parent nodes are expanded so that it is visible. For example:</p> <pre><code>myTreeView.SelectedNode = myTreeView.Nodes[0]; //where 0 is the index of the node you want to select </code></pre> <p>You commented on another answer that you're trying to find the node with the "txt" extension, which suggests that you don't necessarily know the index or location of the node that you want to select in the <code>TreeView</code>. To find it, you'll have to loop through all of the nodes in the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.nodes.aspx" rel="nofollow"><code>TreeView.Nodes</code> collection</a> and look for a match. Once you've found a node matching your criteria, you can set that node item as the selected node:</p> <pre><code>foreach (TreeNode node in myTreeView.Nodes) { if (node.Text.Contains("txt")) //or however you want to find a matching node { myTreeView.SelectedNode = node; } } </code></pre>
 

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