LOOPING all node, sub node child and children item

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

LOOPING all node, sub node child and children item

Post by sal21 »

iterate all element in treeview....

My poor code:

Code: Select all

Private Sub Command2_Click()

Call AGGIORNA(Me.TreeView1)

End Sub
Private Sub AGGIORNA(TVTREE As TreeView)

    Dim N As Node, I As Integer, NOD As Node

    For Each N In TVTREE.Nodes
    
        If N.Image = 4 Then
        
        Debug.Print N.Text ' Is the item with arrow
        
        For Each NOD.Children In N.Children
         Debug.Print N.Text ' here i need to loop  IMPARATO ANTONIO, IMPARATO SALVATORE 
         Next
            
        End If
    Next
    '
End Sub
but when image=7, i need to get the value of node... tath contain this child....

example:
all item IMPARATO ANTONIO, IMPARATO SALVATORE have image=7, i need to get the value of item with arrow (have image=4)
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: LOOPING all node, sub node child and children item

Post by HansV »

Perhaps this?

Code: Select all

Private Sub AGGIORNA(TVTREE As TreeView)
    Dim N As Node, NOD As Node
    Dim I As Integer, M As Integer

    For Each N In TVTREE.Nodes
        If N.Image = 4 Then
            Debug.Print N.Text ' Is the item with arrow
            M = N.Children ' number of children
            Set NOD = N.Child
            For I = 1 To M
                Debug.Print NOD.Text ' here i need to loop  IMPARATO ANTONIO, IMPARATO SALVATORE
                Set NOD = NOD.Next
            Next I
        End If
    Next N
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: LOOPING all node, sub node child and children item

Post by sal21 »

HansV wrote:
30 Jul 2021, 19:19
Perhaps this?

Code: Select all

Private Sub AGGIORNA(TVTREE As TreeView)
    Dim N As Node, NOD As Node
    Dim I As Integer, M As Integer

    For Each N In TVTREE.Nodes
        If N.Image = 4 Then
            Debug.Print N.Text ' Is the item with arrow
            M = N.Children ' number of children
            Set NOD = N.Child
            For I = 1 To M
                Debug.Print NOD.Text ' here i need to loop  IMPARATO ANTONIO, IMPARATO SALVATORE
                Set NOD = NOD.Next
            Next I
        End If
    Next N
End Sub
EXCAT!
You read in my mind...as usual. tks

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: LOOPING all node, sub node child and children item

Post by sal21 »

HansV wrote:
30 Jul 2021, 19:19
Perhaps this?

Code: Select all

Private Sub AGGIORNA(TVTREE As TreeView)
    Dim N As Node, NOD As Node
    Dim I As Integer, M As Integer

    For Each N In TVTREE.Nodes
        If N.Image = 4 Then
            Debug.Print N.Text ' Is the item with arrow
            M = N.Children ' number of children
            Set NOD = N.Child
            For I = 1 To M
                Debug.Print NOD.Text ' here i need to loop  IMPARATO ANTONIO, IMPARATO SALVATORE
                Set NOD = NOD.Next
            Next I
        End If
    Next N
End Sub
HUMMMM....
Now i need to store in array strout the value of debug.print, my code dont work...as usual.

Code: Select all

Private Sub AGGIORNA(TVTREE As TreeView)

    Dim N As Node, NOD As Node
    Dim I As Integer, M As Integer

    For Each N In TVTREE.Nodes
        If N.Image = 4 Then
            'Debug.Print N.Text 'CAMERA
            M = N.Children  'NUMERO OSPITI NELLA CAMERA
            Set NOD = N.Child
            For I = 1 To M
                Set NOD = NOD.Next
                ReDim Preserve STROUT(R) As String
                STROUT(R) = N.Text & "|" & NOD.Text
                R = R + 1
                'Debug.Print NOD.Text 'OSPITI
            Next I
        End If
    Next N
    '
End Sub
error in STROUT(R) = N.Text & "|" & NOD.Text

note:
R is a public integer Dim

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: LOOPING all node, sub node child and children item

Post by HansV »

What is the error message?
And what is the value of R when the error occurs?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: LOOPING all node, sub node child and children item

Post by sal21 »

HansV wrote:
31 Jul 2021, 07:21
What is the error message?
And what is the value of R when the error occurs?
R=0

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: LOOPING all node, sub node child and children item

Post by HansV »

Do you have Option Base 1 at the top of the module? If so, insert the line

Code: Select all

    R = 1
above For Each N In TVTREE.Nodes.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: LOOPING all node, sub node child and children item

Post by sal21 »

HansV wrote:
31 Jul 2021, 09:43
Do you have Option Base 1 at the top of the module? If so, insert the line

Code: Select all

    R = 1
above For Each N In TVTREE.Nodes.
:cheers: :cheers: :cheers: :cheers: :clapping: :clapping: :clapping: