### Expand all Nodes

Expand all TreeView nodes starting at the TreeView Root Node.
`Sub Process_Globals
...
Private TreeView1 As TreeView
...
End Sub`
'Expand all treeview items
'Example: ExpandAllItems(TreeView1.Root)
`Sub ExpandAllItems(ti As TreeItem)
For Each tii As TreeItem In ti.Children
tii.Expanded = True
ExpandAllItems(tii)
Next
End Sub`
'Select the first treeview item with option to expand.
'Example: SelectFirstItem(TreeView1, False)
`Sub SelectFirstItem(tv As TreeView, expanded As Boolean)
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)
'Set expanded
Dim ti As TreeItem = joTV.RunMethodJO("getTreeItem", Array(i))
ti.Expanded = expanded
'EXPAND using JavaObject
' Private joTI As JavaObject = joTV.RunMethodJO("getTreeItem", Array(i))
' joTI.RunMethod("setExpanded", Array(True))
End Sub`
Print all treeitems
ExpandAllItems(TreeView1.Root)
SelectFirstItem(TreeView1, False)
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`
'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: T6C272M2020.htm, ID: 2020