Menu

#13 Set root as SelectedNode

open
nobody
None
5
2007-10-24
2007-10-24
Bruno
No

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

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.