In a previous post I covered how to navigate REST responses using a simple treeview control as well as how to create a Treeview from any jSon object in a few lines of code.
Recursion plays a role in dealing with most kinds of hierarchical linked objects. Here’s how to traverse a treeview.
Looking at the results returned by a Tweet sentiment Rest query to the Excel rest library we can use the Rest Results Explorer to see what came back. Next we want to be able to select which fields we want to transfer to Excel, and this needs some treeView traversal to pass on the status of the applied checkboxes as below.
Code
Private Sub trcJobject_NodeCheck(ByVal node As MSComctlLib.node) ' if we get here then a check has been set on on or off.. ' all the children need to inherit this grantParentNodeCheck node, node.Checked End Sub Private Sub grantParentNodeCheck(parent As MSComctlLib.node, _ Optional check As Boolean = True) Dim child As MSComctlLib.node parent.Checked = check Set child = parent.child While Not child Is Nothing grantParentNodeCheck child, check Set child = child.Next Wend End Sub
See how to traverse a treeview , getting started with recursion and Recursion deep dive for more details