Tree View

Posted on 2006-05-10
Last Modified: 2010-05-03
How can I get The name of the parent node when I click on a sub node. for Example:
Group Name
              Building Name
                         Floor Name
                                      Location Name

If I click on Location Name, how do I get the values for all the Nodes above it in code. (Run-time)

If you dont understand please let me know and I will post my code I've got.
Question by:DickSwart6
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]

    Author Comment

    If you look at my example. Woun't your answer only dive me 'floor name' if I select 'Location name'?

    I'm looking for all the above.
    LVL 142

    Accepted Solution

    into 1 string:

    to loop:

    dim p as Node
    set p = treeview.selectednode
    while not(p.parent is nothing)
      set p = p.parent
      debug.print p.caption

    LVL 6

    Assisted Solution

    Try code given below at Treeview NodeCick Event

    Dim I As Integer

    I = Len(TreeView1.SelectedItem.FullPath) - Len(TreeView1.SelectedItem.Text) - 1

    If I > 0 Then
         MsgBox Left(TreeView1.SelectedItem.FullPath, I)
         MsgBox "This is the Root Node"
    End If
    LVL 22

    Assisted Solution

    Option Explicit

    Private Sub Form_Load()
       Dim i As Long
       Dim nod As Node
       Dim sArray() As String
       tv.Nodes.Add , , "Group Name", "Group Name"
       tv.Nodes.Add "Group Name", tvwChild, "Building Name", "Building Name"
       tv.Nodes.Add "Building Name", tvwChild, "Floor Name", "Floor Name"
       Set nod = tv.Nodes.Add("Floor Name", tvwChild, "Location Name", "Location Name")
       sArray = Split(nod.FullPath, "\")
       Debug.Print "Parent Nodes are:"
       For i = 0 To UBound(sArray) - 1
          Debug.Print sArray(i)
    End Sub
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    point split

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now