Solved

simple treeview question

Posted on 2002-06-08
11
140 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
[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
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

751 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