Classes | GUI > Views

TreeView

A view displaying a tree of items with columns
Location: NOT INSTALLED!

Description

A view that displays a hierarchy of items. It is divided into rows and column: each row represents an item, and each column represents a different data field of the items.

The items are represented in code by instances of TreeViewItem, returned by the various TreeView methods. Top level items are added via the TreeView interface, while child items are added via the TreeViewItem interface, which also allows to manipulate items in more detail after their creation.

Items can be visually sorted with -sort, or by clicking on one of the column headers, if -canSort is enabled.

Each item can hold other views in each of its data fields, which allows for rich graphical interaction. See TreeViewItem: -setView.

Class Methods

Inherited class methods

Instance Methods

Data

.columns

Gets or sets the number of columns (data fields) and their names. When setting a smaller number of columns than the current the extra columns will be removed, and hence all the data stored stored in those columns.

Arguments:

An array of Strings for column names.

.numColumns

The total number of columns (data fields).

.addItem

Append a new top-level item.

Arguments:

strings

An array of Strings (or nil), each for the text of one data field.

Returns:

An instance of TreeViewItem representing the new item.

.insertItem

Insert a new top-level item at index.

Arguments:

index

The position at which to insert the item.

strings

An array of Strings (or nil), each for the text of one data field.

Returns:

An instance of TreeViewItem representing the new item.

.removeItem

Remove the given item. After the item is removed, any usage of the related TreeViewItems will have no effect.

Arguments:

An instance of TreeViewItem.

.numItems

The total number of items.

.clear

Removes all items.

.currentItem

Gets or sets the currently selected item.

Arguments:

An instance of TreeViewItem.

Returns:

An instance of TreeViewItem or nil, if no current item.

.itemAt

The item at index.

.childAt

Alias for -itemAt, provided for compatibility with TreeViewItem.

.addChild

Alias for -addItem, provided for compatibility with TreeViewItem.

.insertChild

Alias for -addChild, provided for compatibility with TreeViewItem.

Appearance

.sort

Sort items by data in column. This works regardless of -canSort.

NOTE: Sorting has no effect on the logical order of the items, it only affects how they are displayed.

Arguments:

column

The integer column index to sort by.

descending

Whether to sort in descending or ascending fashion. The default is ascending.

.columnWidth

Arguments:

column

The integer index of a column

Returns:

Integer width of column in pixels. If column is not in the range 0..(numColumns-1), returns -1.

.setColumnWidth

Sets the width of a column. The rightmost column must extend at least to the right bound of the TreeView.

Arguments:

column

The integer index of the column to modify

width

Integer width in pixels

Interaction

.canSort

Whether the user can sort the items by clicking on a column header.

When setting to true, the items will be sorted immediately according to the current sorting column. While true, the view will also automatically sort new items.

The default is false.

See also: -sort.

Actions

.itemPressedAction

The object to be evaluated when a mouse button is pressed on an item, passing this view as the argument.

.onItemChanged

The object to be evaluated whenever the current item changes, passing this view as the argument.

Inherited instance methods

Examples