?
Solved

treeview root question

Posted on 2003-02-21
4
Medium Priority
?
160 Views
Last Modified: 2012-05-04
I have a treeview which represents the logical command structure of a large organization. It is represented as 3 trees with each tree rooted at a geographic level... CONUS,EUROPE,ASIA. Now in the treeview each of these geographic roots are at the same level. Problem is when I click a child node of CONUS or EUROPE it always reports the root as the first node I added to the entire treeview (ASIA geographic root). I cant hardcode a backup routine as in 'node.parent.parent.parent' as the depth of the trees are dynamic depending on user acess level. So, how to I dynamically return to the logical root of my structure?
0
Comment
Question by:mccainz2
4 Comments
 
LVL 5

Accepted Solution

by:
JMoon5FTM earned 400 total points
ID: 7996393
Every node has a tag property, so you could just store your logical root there.

Set NewNode = TreeView.Nodes.Add(...) 'Whatever
Set NewNode.Tag = TreeView.Nodes("CONUS")

If your tree is filled in some sort of loop (likely), you can use a local variable to hold the root reference so you aren't constantly looking it up.  This can perform better with large sets of data.

Dim RootNode as Node
For Each LogRoot in LogRoots 'or whatever looping structure you're using
   Set RootNode = TreeView.Nodes.Add(...)
   'Now do the child nodes
   For Each LogChild in LogRoot.Children
      ...
   Next
Next
0
 
LVL 27

Expert Comment

by:Dabas
ID: 7996511
I would suggest you use the Key property.

Example of how I would set up your tree:

Dim nde As Node

    With TreeView1.Nodes
   
        Set nde = .Add(, , "Root", "Root") 'One common root
        'Set main three trees
        Set nde = .Add("Root", tvwChild, "CONUS", "CONUS")
        Set nde = .Add("Root", tvwChild, "EUROPE", "EUROPE")
        Set nde = .Add("Root", tvwChild, "ASIA", "ASIA")
       
        'Add a node to Asia section:
       
        Set nde = .Add("ASIA", tvwChild, "A1INDIA", "INDIA")

    End With

Here, I have added the INDIA node with a key that starts with A1. When I traverse the key, the "A" will let me know it belongs to the ASIA group, the 1 that it is level 1.

This example is only to give you a few ideas as to how the key can be used for your purposes, of course you will need to adapt this idea to your application.

In short, by checking the parent's key, you will be able to loop back up the tree until you get to the parent that has the appropriate key level.

Hope this helps!

Dabas
0
 
LVL 5

Author Comment

by:mccainz2
ID: 8000999
the node.fullpath property works for me. WIll use this and parse based on the first "/" to find my logical root. Other levels can easily be determined by splitting the full path into an array and using the array increment appropriately.
0
 

Expert Comment

by:CleanupPing
ID: 8901295
mccainz2:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Suggested Courses

578 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