No announcement yet.

Treeview level

  • Filter
  • Time
  • Show
Clear All
new posts

  • Treeview level

    Is there a simple way to determine on which tree level you are when a tree-part is clicked on a TreeView? (Or do I have to use Treeview_Getparent to determine the level)
    I want to restrict the tree to 4 levels. (users may not add more levels)
    Also: how to detemine the number of entries on a tree-node. (need to limit number of entries). Tried Treeview_GetnextItem, but always get all child items of a node as result.
    (I only want to get one child node's number of entries; and not from sub-nodes from that child)
    Another question that arises: I've got 2 listviews an 2 treeviews. They all use the same icons. Is it possible to share one imagelist between those controls, or do I have to create four (identical) imagelists?
    Seems a waste of resources....

    mailto[email protected][email protected]</A>

    [This message has been edited by Peter Lameijn (edited July 16, 2000).]

    "Simplicity is a prerequisite for reliability"

  • #2
    I do not know of any other way than to climb up the tree
    Function NumParent(Byval hWnd As Long, Byval hItem As Long) As Long
        ' hWnd is the treeview control id
        ' hItem is the currently selected treeview node
        Local hParent As Long
        Local hJunk As Long
        Local nLevel As Long
        nLevel = 0
        hParent = TreeView_GetParent(hWnd,hItem)
        Do While hParent
            Incr nLevel
            hJunk = hParent
            hParent = TreeView_GetParent(hWnd,hJunk)
        Function = nLevel
    End Function
    As far as the total number of nodes, I believe that you will have to keep a copy of the tree in an array and keep track of the total number of array elements. I would suggest using the following structure for the array:

    In my experience this was the easiest to visualize. You can try to use Array Insert and Array Delete to update the array. As far as the images, I do not use them so I would just try it, but it could introduce subtle bugs in a larger program.