Solved

simple treeview question

Posted on 2002-06-08
11
137 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

860 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