TreeGadget()

Syntax

Result = TreeGadget(#Gadget, x, y, Width, Height [, Flags])
Description
Creates a Tree gadget in the current GadgetList. If #PB_Any is used as '#Gadget' parameter, the new gadget number will be returned as 'Result'. #Gadget will be the number returned by EventGadget() command. Once a Tree is created, its list of items is empty.

Each item in the tree has a sublevel value assigned to it, that determines its relation with the item above and below it. Items with the same sublevel belong to the same node, items with a higher sublevel are childitems and so on. This sublevel value can be used to determine the relation between two items by comparing their sublevel values. The 'Flags' parameter of AddGadgetItem() is always required for TreeGadget items and is used to set the sublevel at which the new item should be added. Note that if the function is called with a sublevel at which the item cannot be added, the item will be added at the sublevel where it is possible to add it.

'Flags' are optional and can be composed (using the '|' OR operator) of one of the following constants:
  #PB_Tree_AlwaysShowSelection : Even if the gadget isn't activated, the selection is still visible.
  #PB_Tree_NoLines             : Hide the little lines between each nodes.
  #PB_Tree_NoButtons           : Hide the '+' node buttons.
  #PB_Tree_CheckBoxes          : Add a checkbox before each item.
You can add a 'mini help' to this gadget by using GadgetToolTip().


The following commands can be used to act on the tree content:

- AddGadgetItem(): Add an item (with an optional picture in the standard 16x16 icon size).
- RemoveGadgetItem(): Remove an item (and all its child items).
- ClearGadgetItemList(): Remove all the items.
- CountGadgetItems(): Return the number of items currently in the #Gadget.
- GetGadgetItemState(): Return the current state of the specified item.
- SetGadgetItemState(): Change the current state of the specified item.
- GetGadgetItemText(): Return the current text of the specified item.
- SetGadgetItemText(): Change the current text of the specified item.
- GetGadgetState(): Return the current selected item.
- SetGadgetState(): Change the currently selected item.
- GetGadgetText(): Return the text of the currently selected item.
- SetGadgetText(): Change the text of the currently selected item.
- GetGadgetItemAttribute(): With the following attribute:
  #PB_Tree_SubLevel: Returns the sublevel value of the given item.
- GadgetItemID(): Return the OS handle of the specified item (useful for API functions).

Example:
  If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    TreeGadget(0, 10, 10, 160, 160)                                         ; TreeGadget standard
    TreeGadget(1, 180, 10, 160, 160, #PB_Tree_CheckBoxes|#PB_Tree_NoLines)  ; TreeGadget with Checkboxes + NoLines
    For ID = 0 To 1
      For a = 0 To 10
        AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use 
        AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0)        ; ImageID(x) as 4th parameter
        AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)    ; These are on the 1st sublevel  
        AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1)
        AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1)
        AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1)
        AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again
      Next
    Next
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

Supported OS

All

<- TrackBarGadget() - Gadget Index - UseGadgetList() ->