?
Solved

treeview root question

Posted on 2003-02-21
4
Medium Priority
?
157 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) 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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

765 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