Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何获取treeview子节点的索引?_Vb.net_Winforms - Fatal编程技术网

Vb.net 如何获取treeview子节点的索引?

Vb.net 如何获取treeview子节点的索引?,vb.net,winforms,Vb.net,Winforms,如何获取父节点的子节点的索引?我的树视图是这样的: 根节点1 节点1 节点2 根节点2 节点1 节点2 根节点3 节点1 节点2 例如,我想获得根节点2的子节点索引,我该如何做 'Imports System.Windows.Forms Private Sub trv1_AfterSelect(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles trv1.AfterSelect Dim a As I

如何获取父节点的子节点的索引?我的树视图是这样的:

  • 根节点1
    • 节点1
    • 节点2
  • 根节点2
    • 节点1
    • 节点2
  • 根节点3
    • 节点1
    • 节点2
例如,我想获得根节点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

好的,我已经找到了我的工作,而不是获取所选父节点的子节点的索引,我正在反向操作,现在我将获取所选子节点的父索引。并从下面阐述代码

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

您能解释一下您的示例代码与您的问题的关系吗?如果只需要树视图中的索引(不需要用户交互),则不需要任何事件处理程序(由用户交互触发)。除此之外,代码中还有一个未使用的局部变量
a
。您不应该声明
x
吗?我想知道的是如何确定它属于哪个节点1?它属于根节点1还是根节点2,依此类推。。。。我的想法是获取节点的索引,但子节点的索引与根节点的索引相同。请不要在注释中询问您的实际问题;不是每个人在回答之前都会阅读所有评论。相反,请编辑您的问题。这提高了你收到实际问题答案的机会。这已经是我的问题了,我刚刚重新措辞了