[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Excel - TreeView Control - reading tree items

Posted on 2011-09-25
8
Medium Priority
?
369 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
[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
  • 3
  • 3
8 Comments
 
LVL 35

Accepted Solution

by:
Norie earned 2000 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 35

Expert Comment

by:Norie
ID: 36595347
No problem.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 35

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
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

650 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