Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private TreeView1 As TreeView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
TreeView1.SetCheckBoxesMode
For i1 = 1 To 20
Dim cti As CheckboxTreeItem
cti.Initialize("", "Item #" & i1)
cti.Checked = Rnd(0, 2) = 1
cti.Expanded = True
TreeView1.Root.Children.Add(cti)
For i2 = 1 To Rnd(0, 5)
Dim cti2 As CheckboxTreeItem
cti2.Initialize("", "Subitem #" & i2)
cti2.Checked = Rnd(0, 2) = 1
cti.Children.Add(cti2)
Next
Next
End Sub
Private Sub btnToggle_Click
'Toggle the state of item #3 - subitem #2
'note that this will throw an error if there is no such item. Run again if it happens as the tree is generated randomly
Dim item3 As CheckboxTreeItem = TreeView1.Root.Children.Get(2)
Dim subitem2 As CheckboxTreeItem = item3.Children.Get(1)
subitem2.Checked = Not(subitem2.Checked)
End Sub