Results 1 to 3 of 3

Thread: Is Node Parent or Child - Treeview ??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    NY, USA.
    Posts
    240

    Post

    When using Treeview how do I find out if a node that I have selected is a Parent or a Child. Also if it is a Child how do I find the name of the Parent.

    ------------------
    OmarSwan
    Student
    omarswan@yahoo.com

    "Jesus Lives"

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Posts
    106

    Post

    Put a treeview control on a form and paste this code in....
    Option Explicit

    Dim m_LastX As Single
    Dim m_LastY As Single

    Private Sub Form_Load()
    TreeView1.Nodes.Add , , "Root", "Root"
    TreeView1.Nodes.Add "Root", tvwChild, "child", "child"
    End Sub


    Private Sub TreeView1_Click()
    Dim nodX As Node

    Set nodX = TreeView1.HitTest(m_LastX, m_LastY)
    If Not nodX Is Nothing Then
    If nodX.Children > 0 Then
    Debug.Print "Parent node"
    End If

    If Not nodX.Parent Is Nothing Then
    Debug.Print "Child node"
    Debug.Print "Parent key is " & nodX.Parent.Key
    End If
    End If
    End Sub

    Private Sub TreeView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    m_LastX = x
    m_LastY = y
    End Sub

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Put this code on TreeView_NodeClick event:

    Code:
    Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
        If Node.Parent Is Nothing Then
            MsgBox "Node " & Node.Text & " is a root node."
        Else
            MsgBox "Node " & Node.Text & " is a child to " & Node.Parent.Text
        End If
    End Sub
    ------------------

    Serge

    Software Developer
    Serge_Dymkov@vertexinc.com
    Access8484@aol.com
    ICQ#: 51055819


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width