slobber72
asked on
Treeview - looping through nodes
Hi,
I am simply trying to loop through the nodes of my treeview control with following code:
Compile error - argument not optional - and it highlights the ".Items" section of .Nodes.Item.Key
Any help on guiding me through this would be appreciated.
Best regards,
Craig
I am simply trying to loop through the nodes of my treeview control with following code:
With TaskItemsForm.trvTasks
For Each n In trvTasks
Debug.Print "Key : ", .Nodes.Item.Key, "Text : ", .Nodes.Item.Text
Next n
End With
but I am getting the error :Compile error - argument not optional - and it highlights the ".Items" section of .Nodes.Item.Key
Any help on guiding me through this would be appreciated.
Best regards,
Craig
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Martin,
I am getting an error when trying to call your procedure- as I am hopeless with VBA in Excel I can't track down what the reason for it is.
When I call the procedure as below, I get the error "Type Mismatch"...
Could you perhaps point me in the right direction as to what I am doing wrong ?
Thanks in advance.
Craig
I am getting an error when trying to call your procedure- as I am hopeless with VBA in Excel I can't track down what the reason for it is.
When I call the procedure as below, I get the error "Type Mismatch"...
Private Sub UserForm_Initialize()
With Me
'Label the userform
.Caption = "Menu Tasks Comment Form"
' Label the buttons
.CommandButton1.Caption = "Close"
.CommandButton2.Caption = "Add Comment"
.CommandButton3.Caption = "View Comments"
.Frame1.Caption = "Comments"
'Null out the label
.Label1 = vbNullString
.TextBox1 = vbNullString
'Label the treeview
.TreeView1.LineStyle = tvwRootLines
'Sort the treeview
.TreeView1.Sorted = True
End With
'Populate the Treeview
TreeView_Populate True ' populate the treeview control
WalkTree Me.TreeView1.Nodes(1)
End Sub
Could you perhaps point me in the right direction as to what I am doing wrong ?
Thanks in advance.
Craig
ASKER
Hi again,
I found that I needed to change the procedure to declare the parentnode as an object, not as a node - it would appear that this is a version of treeview issue.
Thanks again !!
I found that I needed to change the procedure to declare the parentnode as an object, not as a node - it would appear that this is a version of treeview issue.
Private Sub WalkTree(ByVal ParentNode As Object) ' previously declared as node
Do Until ParentNode Is Nothing
Debug.Print ParentNode.Text, , ParentNode.Index, , ParentNode.Key
WalkTree ParentNode.Child
Set ParentNode = ParentNode.Next
Loop
End Sub
Thanks again !!
I'm glad you were able to fix it. Not that I'm complaining but what happened between the time you said my code worked really well and the type mismatch error?
Just out of curiosity, does the following work for you?
Private Sub WalkTree(ByVal ParentNode As ComctlLib.Node)
Just out of curiosity, does the following work for you?
Private Sub WalkTree(ByVal ParentNode As ComctlLib.Node)
ASKER