### Print all TreeView nodes

Print all TreeView nodes starting at the TreeView Root Node.
Private TreeView1 As TreeView
'Print all treeitems.
'Example expanding all treeitems, set the first treeitem to then print all
'ExpandAllItems(TreeView1.Root)
'tvSetFirst(TreeView1)
'PrintAllItems(TreeView1, TreeView1.Root)
`Sub PrintAllItems(tv As TreeView, ti As TreeItem)
For Each tii As TreeItem In ti.Children
Dim index As Int = tvSetItemSelected(tv, tii)
Log(index & "=" & tii.Text)
PrintAllItems(tv, tii)
Next
End Sub`
'Expand all treeitems
'ExpandAllItems(TreeView1.Root)
'tvSetFirst(TreeView1)
`Sub ExpandAllItems(ti As TreeItem)
For Each tii As TreeItem In ti.Children
tii.Expanded = True
ExpandAllItems(tii)
Next
End Sub`
`Sub tvSetFirst(tv As TreeView)
If Not(tv.IsInitialized) Then Return
Private joTV As JavaObject = tv
joTV.RunMethodJO("getSelectionModel", Null).RunMethod("selectFirst", Null)
Dim i As Int = joTV.RunMethodJO("getSelectionModel", Null).RunMethod("getSelectedIndex", Null)
Private joTI As JavaObject = joTV.RunMethodJO("getTreeItem", Array(i))
joTI.RunMethod("setExpanded", Array(True))
End Sub`
'Set a treeitem selected. Returns the selected index
`Sub tvSetItemSelected(tv As TreeView, ti As TreeItem) As Int
Dim joTV As JavaObject = tv
Dim joMSM As JavaObject = joTV.RunMethod("getSelectionModel", Null)
joMSM.RunMethod("select", Array(ti))
Return joTV.RunMethodJO("getSelectionModel", Null).RunMethod("getSelectedIndex", Null)
End Sub`

Changed: , Category: TreeView, File: T6C272M2024.htm, ID: 2024