Solved

Excel - TreeView Control - reading tree items

Posted on 2011-09-25
8
327 Views
Last Modified: 2012-05-12
I have a TreeView control on a UserForm which is populated from a 'map structure' in a database table.

I can make it possible to drag and drop between nodes.

Now I want to be able to 'read' the modified TreeView so that I can upload the map back to the database.

Does anybody know how to 'read' the TreeView?
ie. from the Root read each node and child nodes etc. loop through all.
te. Extract ParentID, Name, ThisItemID.

Thanks.
0
Comment
Question by:hindersaliva
  • 3
  • 3
8 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 36595332
Where do you want to 'read' it to?

eg an array, onto a worksheet, straight into the database

What you can do is use a recursive sub like this:
Public Sub TraverseTree(objNode As Node)
Dim objSiblingNode As Node
Dim strResults As String


    Set objSiblingNode = objNode

    Do
        strResults = strResults & objSiblingNode.Text & vbCrLf

        Debug.Print objSiblingNode.Text

        If Not objSiblingNode.Child Is Nothing Then
            Call TraverseTree(objSiblingNode.Child)
        End If

        Set objSiblingNode = objSiblingNode.Next

    Loop While Not objSiblingNode Is Nothing

End Sub

Open in new window

That's a very simple example that can be adapted for other purpose.

For example, I've used it in the past to populate an array.
0
 

Author Comment

by:hindersaliva
ID: 36595340
imnorie,
That's exactly what I was after. I shall load it into an array (and then have several selectable choices).

Thanks!
0
 
LVL 33

Expert Comment

by:Norie
ID: 36595347
No problem.

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:hindersaliva
ID: 36595575
Imnorie,
I'm struggling with how to start it off.
Do you have a code sample that calls the Sub? ie. with the initial value of objNode
For me it will be the Root.

(This is exciting)

Thanks
0
 
LVL 33

Expert Comment

by:Norie
ID: 36595590
Something like this perhaps.
Dim ptnode As Node

    Set ptnode = TreeView1.Nodes("Root")
    Call TraverseTree(ptnode)

Open in new window

This will only work if your 'root' node has the key value 'Root'.

If it has something different use that.
0
 

Author Comment

by:hindersaliva
ID: 36596267
imnorie
Yes that worked great.
Thanks
0
 
LVL 50

Expert Comment

by:teylyn
ID: 37412263
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Macro to Send Appointment from Excel 1 30
onOpen 14 43
Cells protection in Excel 7 22
EXCEL formula help required 3 15
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

746 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

12 Experts available now in Live!

Get 1:1 Help Now