Set root as SelectedNode
Brought to you by:
agaman
When retrieving the root node with
TreeNodeAdv root = tree.FindNode(TreePath.Empty);
and setting this root node as the SelectedNode:
tree.SelectedNode = root;
a NullReferenceException occurs in
EnsureVisible(TreeNodeAdv node):
public void EnsureVisible(TreeNodeAdv node)
{
if (node == null)
throw new ArgumentNullException("node");
if (!IsMyNode(node))
throw new ArgumentException();
TreeNodeAdv parent = node.Parent; // parent is null when node is rootNode
while (parent != _root)
{
parent.IsExpanded = true; // NullReference
parent = parent.Parent;
}
ScrollTo(node);
}
Checking for parent == null in the while loop corrects the problem.
Regards,
Bruno