开发者

How do you make the TreeView.SelectedNode property nulled without nulling the current node in the SelectedNode?

If TreeView.SelectedNode = null开发者_StackOverflow is used, would it also null the node object on the SelectedNode?


You appear to be confusing references and objects. You can have a null-reference (which refers to no object at all), but there is no such thing as a null-object in C#.

If on the other hand, you are concerned that setting the SelectedNode property to null will evict the currently selected node from the TreeView, this is not the case - that node will simply be unselected.

EDIT: Perhaps you are concerned that the values of other variables that hold references to the currently-selected node will be set to null should the SelectedNode property be set to null. This is not the case either:

TreeView treeView = ...

TreeNode node = new TreeNode();    
treeView.Nodes.Add(node);

treeView.SelectedNode = node;

treeView.SelectedNode = null; 
bool isNodeNull = (node == null); // false


No. The SelectedNode property refers only to the node that is currently selected, so you can set it to null without "nulling the node object" itself. It will simply de-select whatever node is currently selected in the TreeView control.

According to the documentation:

If no TreeNode is currently selected, the SelectedNode property is Nothing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜