C# 如何清除 TreeView 中选定节点的选择?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11824443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I clear the selection of a selected node in a TreeView?
提问by Marshall
How to deselect selected node (in after select event)?
如何取消选择选定的节点(在选择事件之后)?
采纳答案by gideon
When you are faced with issues like this (dealing with what api you need to use) You should consult MSDN and then figure it out.
当您遇到这样的问题(处理您需要使用什么api)时,您应该咨询MSDN,然后弄清楚。
Now, see the TreeViewpage on msdn. It has a Selectednodeproperty which says :
现在,查看msdn 上的TreeView页面。它有一个Selectednode属性,它说:
If no TreeNode is currently selected, the SelectedNode property is null.
如果当前未选择 TreeNode,则 SelectedNode 属性为 null。
Also, it has a getterand setter. So my best bet is:
此外,它还有一个getter和setter。所以我最好的选择是:
myTreeView.SelectedNode = null;//will deselect it

