Solved

Treeview to RichTextBox import

Posted on 2015-01-11
5
75 Views
Last Modified: 2015-01-12
Hello,
I have a small project. In one point I couldnt succed to solve again.
In my project , I have one treeview ( called tv ), and one command button. In my project in Form_Load event , I have some INFITF application codes which provides some information to establish treeview.
ın the attachment , I can export treeview nodes in order to Richtext box, no problem. But when I am importing to richtextbox, I need some additional events.
What I want:
- when I am sending the treeview nodes to Richtext box, I want to add some suffix to treeview nodes.
If my node has sub nodes -  when I am sending , I want to add (.Zeta) suffix at the end, and if there is sub nodes ı want to add (.Beta) suffix at the ends.
For example lets say that my treeview like that

      -AA
        .
        .
        -BB
          .BB1
          .BB2
        .
        .
        -CC
          .CC1
          .CC2
        .
        .DD
        .
        .EE

And my Richtextbox:
AA
BB
BB1
BB2
CC
CC1
CC2
DD
EE

The thing that I want:

AA.Zeta
BB.Zeta
BB1.Beta
BB2.Beta
CC.Zeta
CC1.Beta
CC2.Beta
DD.Beta
EE.Beta

ı am attaching to my project, but I deleted my form_load event because of my INFITF application which will not work on your computer. So you can write some thing there to establih your treeview.
Can you help me for this point?
Project.zip
0
Comment
Question by:hakanogu
  • 3
  • 2
5 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40543526
Let me see what I can do for you here.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 40543529
Try this:
Public Sub WalkTree(objNode As Node)
    'Bu kod treeviewlardaki node isimlerinin text1 kontrolunun içine atilmasini sagliyor
    Dim objSiblingNode As Node
    
    Set objSiblingNode = objNode
    
    Do
'        RichTextBox1.Text = RichTextBox1.Text & objSiblingNode.Text & vbCrLf
        If objNode.Parent Is Nothing Then
            RichTextBox1.Text = RichTextBox1.Text & objSiblingNode.Text & ".Zeta" & vbCrLf
        Else
            RichTextBox1.Text = RichTextBox1.Text & objSiblingNode.Text & ".Beta" & vbCrLf
        End If


        If Not objSiblingNode.Child Is Nothing Then
            Call WalkTree(objSiblingNode.Child)
        End If
        Set objSiblingNode = objSiblingNode.Next
    Loop While Not objSiblingNode Is Nothing
End Sub

Open in new window

0
 

Author Comment

by:hakanogu
ID: 40543824
Hello Martin,
I tried the code but it just gives the root as (.Zeta), all the other is becoming (.Beta)
0
 

Author Comment

by:hakanogu
ID: 40543855
Ok Martin i solved the problem with your help
If I correct your code instead of "objNode.Parent " with  "objSiblingNode.Child" in your firs is working.

        If Not objSiblingNode.Child Is Nothing Then
            RichTextBox1.Text = RichTextBox1.Text & objSiblingNode.Text & ".Zeta" & vbCrLf
        Else
            RichTextBox1.Text = RichTextBox1.Text & objSiblingNode.Text & ".Beta" & vbCrLf
        End If

If you send the new code by changing , i will accept your answer Martin.
Thank you very much for your help.
0
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40544125
Public Sub WalkTree(objNode As Node)
    'Bu kod treeviewlardaki node isimlerinin text1 kontrolunun içine atilmasini sagliyor
    Dim objSiblingNode As Node
    
    Set objSiblingNode = objNode
    
    Do
'        RichTextBox1.Text = RichTextBox1.Text & objSiblingNode.Text & vbCrLf
        If Not objSiblingNode.Child Is Nothing Then
            RichTextBox1.Text = RichTextBox1.Text & objSiblingNode.Text & ".Zeta" & vbCrLf
        Else
            RichTextBox1.Text = RichTextBox1.Text & objSiblingNode.Text & ".Beta" & vbCrLf
        End If


        If Not objSiblingNode.Child Is Nothing Then
            Call WalkTree(objSiblingNode.Child)
        End If
        Set objSiblingNode = objSiblingNode.Next
    Loop While Not objSiblingNode Is Nothing
End Sub

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

9 Experts available now in Live!

Get 1:1 Help Now