B4J v1.05 adds support for the TreeView node.
TreeView as it name suggests visualizes a tree structure.
Each item in the TreeView is a TreeItem (or CheckBoxTreeItem). Each item has a list of children items.
Example:
Items are added to the root TreeItem. The root itself is not visible.
You can add an image to each of the items by setting the Image property.
TreeItem raises a single event which is the ExpandedChanged event. You can use the Sender keyword to get the TreeItem that raised the event:
CheckBoxTreeItem
The TreeView can show checkboxes before each of the items.
This is done by:
- Calling TreeView.TreeView1.SetCheckBoxesMode
- Adding CheckBoxTreeItems instead of TreeItems.
CheckBoxTreeItems raise the CheckedChange event (and ExpandedChanged event).
TreeView as it name suggests visualizes a tree structure.
Each item in the TreeView is a TreeItem (or CheckBoxTreeItem). Each item has a list of children items.
Example:
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private TreeView1 As TreeView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
TreeView1.Initialize("TreeView1") 'here we create it by code. Usually you will add it with the builder.
MainForm.RootPane.AddNode(TreeView1, 0, 0, 400, 400)
'add 10 items, each with a child item
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
TreeView1.Root.Children.Add(ti) 'add the father to the root
Next
End Sub
Items are added to the root TreeItem. The root itself is not visible.
You can add an image to each of the items by setting the Image property.
TreeItem raises a single event which is the ExpandedChanged event. You can use the Sender keyword to get the TreeItem that raised the event:
B4X:
Sub TI_ExpandedChanged(Expanded As Boolean)
Dim ti As TreeItem = Sender
Log(ti.Text & ": " & Expanded)
End Sub
CheckBoxTreeItem
The TreeView can show checkboxes before each of the items.
This is done by:
- Calling TreeView.TreeView1.SetCheckBoxesMode
- Adding CheckBoxTreeItems instead of TreeItems.
CheckBoxTreeItems raise the CheckedChange event (and ExpandedChanged event).