# The MIT License (MIT)
#
# Copyright (C) 2026 Scott Duensing
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

.topic ctrl.treeview
.title TreeView
.toc 1 TreeView
.index TreeView
.index AddItem
.index AddChildItem

.h1 TreeView

VB Equivalent: TreeView -- DVX Widget: treeview

A hierarchical tree of expandable/collapsible nodes. Supports multi-select and drag-to-reorder. Items are accessed by depth-first index (0-based).

.h2 Type-Specific Methods

.table
  Method                                  Description
  ------                                  -----------
  AddChildItem parentIndex%, text$        Add a child node under the node at the given index.
  AddItem text$                           Add a root-level node.
  Clear                                   Remove all nodes.
  GetItemText$(index%)                    Returns the text of the node at the given index.
  IsExpanded(index%)                      Returns True if the node at the given index is expanded.
  IsItemSelected(index%)                  Returns True if the node at the given index is selected.
  ItemCount()                             Returns the total number of nodes (all levels).
  SetExpanded index%, expanded            Expand or collapse the node at the given index.
  SetItemSelected index%, selected        Select or deselect the node at the given index.
  SetMultiSelect multi                    Enable or disable multi-select mode.
  SetReorderable reorderable              Enable or disable node reordering.
.endtable

Default Event: Click

.h2 Example

.code
TreeView1.AddItem "Animals"
TreeView1.AddChildItem 0, "Cat"
TreeView1.AddChildItem 0, "Dog"
TreeView1.AddItem "Plants"
TreeView1.AddChildItem 3, "Oak"
TreeView1.SetExpanded 0, True
Print "Items:"; TreeView1.ItemCount()
.endcode

.link ctrl.common.props Common Properties, Events, and Methods
