Solved

simple treeview question

Posted on 2002-06-08
11
133 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

863 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

23 Experts available now in Live!

Get 1:1 Help Now