### Get all Children

To get all children from a TreeView, a recursive routine can be used like shown below.
' Get all the children of a TreeView
' A recursive routine is used to log the TreeItem text
`Sub getAllChildren(tv As TreeView)
For i = 0 To tv.Root.Children.Size - 1
PrintRecursive(tv.Root.Children.Get(i))
Next
End Sub`
' Loop recursive over treeitem children and log the treeitem text
`Sub PrintRecursive(ti As TreeItem)
Log(ti.Text)
Dim aNode As TreeItem
For Each aNode As TreeItem In ti.Children
PrintRecursive(aNode)
Next
End Sub`
' Test Items
' Add 10 treeitems, each with a child item and a child
`Sub loadTreeview
For i = 1 To 10
Dim ti As TreeItem
ti.Initialize("ti", "Item #" & i)
Dim cti As TreeItem
cti.Initialize("ti", "My father is Item #" & i)
ti.Children.add(cti) 'add the child
Dim cti2 As TreeItem
cti2.Initialize("cti", "My father is Sub Item #" & i)
cti.Children.add(cti2) 'add the child
TreeView1.Root.Children.add(ti) 'add the father to the root
Next
End Sub`
' A test button
`Sub buttonTest_Action
Log("Load TreeView with Test Items.")
loadTreeview
Log("Get Children...")
getAllChildren(TreeView1)
End Sub`
Hints
To get the number of treeitems in the TreeView add a counter. Example:
`Sub Process_Globals
...
Dim FCnt As Int = 0
...
End Sub`
Increase counter in PrintRecursive
...
Log(ti.Text)
FCnt = FCnt + 1

Changed: , Category: TreeView, File: T6C272M2021.htm, ID: 2021