treeview控件如何获取当前选中的节点名和节点的位置
Private Sub TreeView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseClick
MsgBox(TreeView1.SelectedNode.Index.ToString)
End Sub
我的代码如上,报错说“没把设置引用到对象中”。问题如题!请问如何做到,百度了几下没有找到,有人说用afterselect事件,但是我想在我单击treeview控件时就做其它事情。请大虾指教!! TreeView vb.net
[解决办法]
MSDN:
Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles TreeView1.AfterSelect
' Display the Text and Index of the
' selected tree node's Parent.
If (e.Node.Parent IsNot Nothing) Then
If (e.Node.Parent.GetType() Is GetType(TreeNode)) Then
MsgBox("Parent: " + e.Node.Parent.Text + ControlChars.Cr + "Index Position: " + e.Node.Index.ToString())
End If
Else
MsgBox("No parent node.")
End If