比如:  Set nodx = Treeview1.Nodes.Add(, tvwFirst, "A", "测试A")
    Set nodx = Treeview1.Nodes.Add("A", tvwChild, "A1", "A")
     Set nodx = Treeview1.Nodes.Add("A", tvwChild, "A2", "AA")
      Set nodx = Treeview1.Nodes.Add("A", tvwChild, "A3", "AAA")
 Set nodx = Treeview1.Nodes.Add(, tvwFirst, "B", "测试B")
    Set nodx = Treeview1.Nodes.Add("B", tvwChild, "B1", "B")
     Set nodx = Treeview1.Nodes.Add("b", tvwChild, "B2", "BB")--A
-----A
-----AA
-----AAA
--B
_____B
-----BB
我要控制的是
如果点击 Root是A里面的子节点 就Msgbox "A"
如果点击 Root是B里面的子节点 就Msgbox "B"我写的,
      If Node.Root.Text = "A" Then
        msgbox "a"
         elseif Node.Root.Text = "B" then
        msgbox "b"
       Endif                      但是不行啊~~~~~~~~~~~~~~~~~ 谁帮我控制一下。

解决方案 »

  1.   

    用父节点属性判断
    If Node.Parent.Text="A" Then
        Msgbox "A"
    End If
      

  2.   

    那怎么使 parent.text="B"的子节点全部收起来呢。
      

  3.   

    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
        If Not (Node.Parent Is Nothing) Then MsgBox Node.Parent.Text
    End Sub
      

  4.   

    TreeView1.Nodes(1).Expanded = False '使索引为1的收起来~
      

  5.   

    Re: lilaclone(~~阿九~~) 我怎么一点A就出错了呢~~ 91错误。对象变量或with块变量未设置。
      

  6.   

    cuizm(射天狼) 的意思是只要是节点下面还有节点,不为空,就是父节点。但是我不是这个意思啊~  我不是要判断是不是父节点,我要判断哪一个父节点阿。阿九的意思是对的,但是好像和我写的那个一样。 有问题~
      

  7.   

    继续顶~~  能不能用key来控制阿? 怎么控制?
      

  8.   

    我觉得射天朗说得对呀。
    If Not (Node.Parent Is Nothing) Then MsgBox Node.Parent.Text
    判断了是否有父节点,是对应父节点的text(Node.Parent.Text)