Solved

simple treeview question

Posted on 2002-06-08
11
132 Views
Last Modified: 2010-05-02
Hi,
i need to print the content of a treee veiw as they are i mean print the father then its childred under it like:
1
  11
  12
    121
    122
    123
  13
2
 21
   211
   212
 22
 23
i need to print them on the printer but i dont want to use the indexs coz it will print them as levels i mean it will print the whole first level then the whole second level and so on  

thanx for help
Loay
0
Comment
Question by:loay
11 Comments
 

Expert Comment

by:trowa
ID: 7065014
Do a loop to compare each node in TreeView, if it's child then Add vbTab to the string to print.
0
 

Author Comment

by:loay
ID: 7065070
i know this but how can i write it you know i need aloop to check if it is a parent or not and if it a parent prints its child then go and print the second parent and its child but how to write this code
0
 
LVL 5

Expert Comment

by:Julian_K
ID: 7065115
Hello.
Here is a very simple answer to your problem, but it uses recursion. The recursion level depends on how many times an item has a child. I mean:
if there is a CHILD that has a CHILD that has a CHILD that has a CHILD - this is level 4 recursion.

The code that follows is usefull, if the recursion level will be not more than... let's say 100 ;-)


Private Sub PrintTreeView(ByVal Item As MSComctlLib.Node)
   
    Do Until (Item Is Nothing)
        Printer.Print Item.Text
        If Item.Children > 0 Then PrintTreeView(Item.Child)
        Set Item = Item.Next
    Loop
   
End Sub

I hope it will be useful

Julian.
0
 

Author Comment

by:loay
ID: 7066150
Hi Julian,
first thanx for trying help me ,, i tyoed ur code but the problem is when i wana call it i tried many things to send them as parameters but it was always say "type missmatch" so please can u tell me how can i call the procedure and send my tree to it

thanx alot
Loay
0
 
LVL 5

Expert Comment

by:Julian_K
ID: 7066659
Hello, loay.
Sorry for this confusion.
The parameter you have to send to this procedure is an object of type "Node" - an item from the treeview. It must be the first sibling, if you want to print the whole tree. So, let's say you have a:
 TreeView control called "TreeView1"
 Command Button called "Command1"

your code would look like this:
-------------------------------

Private sub Command1_Click()
   Call PrintTreeView(TreeView1.Nodes(1))
End Sub

Try it and call back. I'l be online again tomorrow morning :-)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:loay
ID: 7066817
hi again thanx again for ur support but this time it gives me an error on the
 if Item.Children > 0 Then PrintTreeView(Item.Child)
and it says "type missmatch" ,, so what should i do to solve this problem

thanx alot again
 
       
0
 
LVL 2

Expert Comment

by:i_jester69
ID: 7068778
Just get rid of the parentheses around the item.child parameter or use the 'Call' methodology:

Private Sub PrintTreeView(ByVal Item As MSComctlLib.Node)
   
   Do Until (Item Is Nothing)
       Printer.Print Item.Text
       If Item.Children > 0 Then PrintTreeView Item.Child
       Set Item = Item.Next
   Loop
   
End Sub

Private Sub PrintTreeView(ByVal Item As MSComctlLib.Node)
   
   Do Until (Item Is Nothing)
       Printer.Print Item.Text
       If Item.Children > 0 Then Call PrintTreeView(Item.Child)
       Set Item = Item.Next
   Loop
   
End Sub
0
 
LVL 5

Accepted Solution

by:
Julian_K earned 55 total points
ID: 7069501
Oh, How STUPID I AM !!! :-((

The problem is in the brackets in line 4:

Private Sub PrintTreeView(ByVal Item As MSComctlLib.Node)
1:   Do Until (Item Is Nothing)
2:     Printer.Print Item.Text
3:     If Item.Children > 0 Then PrintTreeView (Item.Child)
4:     Set Item = Item.Next                   '^^^^^^^^^^^^
5:   Loop
   
End Sub

It must be like:
  if Item.Children > 0 then PrintTreeView Item.Child

I am very sorry for this stupid bug of mine...
0
 

Author Comment

by:loay
ID: 7069564
ok thanx alot it is working fine now but please can u explain to me why when we use the brackets it gives that error.. and what is the defferent between calling with () and without them

any way if u can answer me it is cool i will wait for tom. and i wil send u ur points if u can explain it is good if cant no problem u helped me alot

loay


and thanx alot for i_jester69  u helped me alot.
0
 
LVL 5

Expert Comment

by:Julian_K
ID: 7069660
When You use brackets (I mean brackets that are around an expression, not the ones that are needed to be put around parameters), VB decides, that this is an expresion and tries to evaluate it internaly, so When you pass object into brackets, It evaluates it as a variant of subtype object. I think that is what happens. Really Stupid :-)))

0
 

Author Comment

by:loay
ID: 7069789
thanx for clearation and i hope to be friends ... thanx alot
Loay
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

760 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

22 Experts available now in Live!

Get 1:1 Help Now