C# 如何在树视图中获取当前选定的节点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8861624/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 04:51:15 来源:igfitidea点击:
How to get currently selected node in a treeview
提问by Mike
How is it possible to get the selected (clicked on) node in a treeview and return it as a string?
如何在树视图中获取选定(单击)的节点并将其作为字符串返回?
采纳答案by ken2k
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string selectedNodeText = e.Node.Text;
}
回答by rene
From the docs:
从文档:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode.aspx
Maybe:
也许:
MessageBox.Show(((TreeView)sender).SelectedNode.Text)
Or
或者
MessageBox.Show(((TreeView)sender).SelectedNode.Name)

