Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TreeView Control - How to determine the level of a node

Status
Not open for further replies.

Maturi

IS-IT--Management
Oct 9, 2003
81
0
0
GB
Hi

I am using a TreeView Control (MS V6.0) in Access 2000. It works fine.

For a given node I want to be able to determine the level of the node (I presume the root is level 0, child nodes under that will be level 1 and so on)

The treeview control is called TV1 and I can access vairous properties of the node like 'Text' and 'Key' using Me!TV1.Text and Me!TV1.Key.

But I don't know how to get the level.

I read somewhere that in ASP.NET there is a function called NodeLevel(node) that returns the level - is there something similar in Access/VB ??

Thanks
 
The Node.FullPath property is a string with "\" seperators. Count these and you've got the level.

Or

Do
If Node.Parent Is Nothing then
Exit Do
End If
Set Node = Node.Parent
NodeLevel = NodeLevel + 1
Loop

Neither are very elegant (but would work) so I'd be interested if anyone else has other ideas!
 
about the same idea
Code:
Public Function getLevel(theNode As Node) As Integer
  getLevel = 1
  Do Until theNode.Root = theNode.FirstSibling
    getLevel = getLevel + 1
    Set theNode = theNode.Parent
  Loop
End Function
 
PS

The Root is the very first node in your tree. The first sibling is the first node in a level.
 
I am having problems getting proper focus on controls in forms that I open via a selection from a treeview. When the frontend of my access database opens I default to opening a main menu form containing a treeview whose nodes are created from a table in the database. The node info includes an action and action arguement. On the node_click event for the treeview I inspect the selected node id and determine the action to perform on the given argument. In cases where the action is to open a form I cannot get the focus on a control in the opened form. I've tried doing this in the forms activate event as well as within the treeview node_click event but can't get it to work. I have to click on the main form and then on the form I've just opened to gain focus on the control (or just simply click directly on the control). It seems that the treeview maintains focus and I can't find a way of taking focus off the main menu with the treeview. Anyone seen this before?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top