PDA

Click to See Complete Forum and Search --> : Is Node Parent or Child - Treeview ??


omarswan
Dec 13th, 1999, 02:44 PM
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"

hayessj
Dec 13th, 1999, 03:28 PM
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

Serge
Dec 13th, 1999, 06:06 PM
Put this code on TreeView_NodeClick event:


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 (http://www.icq.com/51055819)