### Create TreeView CheckboxItems

An example of creating a TreeView with CheckBox TreeItems.
B4J Documentation:
http://www.b4x.com/b4j/help/jfx.html#checkboxtreeitem
Note: Not the full code is shown, onley TreeView relevant.
`Sub Process_Globals
...
Private TreeView1 As TreeView
...
End Sub`
`Sub AppStart (Form1 As Form, Args() As String)
...
AppInit
End Sub`
`Sub AppInit
Dim l As List
Dim img As Image
'Set the image
img.Initialize(File.DirAssets, "folder.png")
'Build some test items
l.Initialize
For i = 0 To 4
l.Add("Item " & i)
Next
'Add to the TreeView
'TreeView1.Root.Children.AddAll(l)
For i = 0 To 4
Dim CheckboxItem As CheckboxTreeItem
CheckboxItem.Initialize("CheckboxItem", l.Get(i))
CheckboxItem.Image = img
TreeView1.Root.Children.Add(CheckboxItem)
Dim idx As Int = TreeView1.Root.Children.IndexOf(CheckboxItem)
Dim ti As TreeItem = TreeView1.Root.Children.Get(idx)
For j = 0 To 1
Dim CheckboxItemC As CheckboxTreeItem
CheckboxItemC.Initialize("CheckboxItem", l.Get(i) & "-" & j )
ti.Children.Add(CheckboxItemC)
Next
ti.Expanded = True
Next
TreeView1.SetCheckBoxesMode
TreeView1.Root.Expanded = True
End Sub`
'Get the state of the selected checkboxitem
`Sub CheckboxItem_CheckedChange(Checked As Boolean)
Dim CheckboxItem As CheckboxTreeItem = Sender
Log("CheckBoxItemChanged to " & Checked & " for " & CheckboxItem.Text)
End Sub`
'Handle Selected Item change
`Sub TreeView1_SelectedItemChanged(SelectedItem As TreeItem)
Dim idx As Int = TreeView1.Root.Children.IndexOf(SelectedItem)
Dim CheckboxItem As CheckboxTreeItem = TreeView1.Root.Children.Get(idx)
Log("SelectedItemChanged: " & SelectedItem.Text & ", State is " & CheckboxItem.Checked)
End Sub`
'Collate the checkmenu items text and state from the checkboxtree
' Dim TreeList As List
' TreeList.Initialize
' CollectCheckBoxTreeItems(TreeList, TreeView1.Root.Children)
' For i = 0 To TreeList.Size - 1
' Log(TreeList.Get(i))
' Next
`Private Sub CollectCheckBoxTreeItems(TreeItems As List, Items As List)
For Each ti As TreeItem In Items
Dim CheckboxItem As CheckboxTreeItem = ti
TreeItems.Add(ti.Text & " = " & CheckboxItem.Checked)
If ti.Children.Size > 0 Then
CollectCheckBoxTreeItems(TreeItems, ti.Children)
End If
Next
End Sub`

Changed: , Category: TreeView, File: T6C272M2019.htm, ID: 2019