如何获取父节点的子节点的索引?我的树视图是这样的:
例如,我想获取Root节点2的子节点索引,我该怎么做?
'Imports System.Windows.Forms
Private Sub trv1_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles trv1.AfterSelect
Dim a As Integer
x = e.Node.Index
debug.print x
End Sub
答案 0 :(得分:0)
好的我已经完成了我的工作而不是获取所选父节点的子节点的索引我正在反向执行它将立即获得所选子节点的父索引。并从下面阐述代码
Private Sub treeView1_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles treeView1.AfterSelect
If (e.Node.Parent IsNot Nothing)
If (e.Node.Parent.GetType() Is GetType(TreeNode)) Then
label1.Text = "Parent: " + e.Node.Parent.Text + _
ControlChars.Cr + "Parent Index: " + e.Node.Parent.Index.ToString()
End If
Else
label1.Text = "No parent node."
End If
End Sub