Try this:
TreeNode currentNode = treeView.SelectedNode;
while (currentNode.Parent != null)
{
currentNode = currentNode.Parent;
}
You are iterating from some node (does not matter which one) and go up the hierarchy until the Parent
of the current node is null
, that is, the current node is the Root
.
Also, here is the class reference for the TreeView:
You will be able to figure out, from the class reference that
sort(mytv.Nodes)
did not work because Nodes is not a node but rather a collection of nodes.
Also, the TreeView does not have a TopNode
attribute.