Treeview
A multi-column list or tree. Each row is an item with a text label (the #0
column) and optional cell values in named data columns.
Live preview
Try the Theme switcher in the toolbar — this preview restyles live:
Live preview. In the Player's built-in docs viewer (
scriptweaver --help), this rendersTreeviewas a live, theme-aware widget you can interact with.
Example
const tv = app.Treeview({ columns: 'size kind', show: 'tree headings' });
tv.heading('#0', { text: 'Name' });
tv.heading('size', { text: 'Size' });
tv.pack.configure({ fill: 'both', expand: true });
const id = tv.insert('', 'end', { text: 'report.txt' });
tv.set(id, 'size', '12 KB');
tv.set(id, 'kind', 'file');
columns names the data columns; show is 'tree', 'headings', or both.
Items
| Method | Description |
|---|---|
insert(parent, index, opts?) |
Add an item; returns its id. parent is '' for top level. opts: text, values, open, image, tags. |
children(parent) |
Child item ids of parent ('' = top level). |
delete(...ids) / detach(...ids) |
Remove / unlink items. |
move(id, parent, index) |
Re-parent or reorder. |
parentOf(id) / indexOf(id) / exists(id) |
Navigation and existence. |
Cells, columns & headings
| Method | Description |
|---|---|
getText(id) / setText(id, s) |
The #0 (tree) label. |
get(id, column) / set(id, column, value) |
A data-column cell value. |
column(col, opts) |
Configure a column (width, anchor, …). |
heading(col, opts) |
Configure a heading (text, …). |
Selection
| Method | Description |
|---|---|
selection() |
Selected item ids. |
selectionSet(...ids) / selectionAdd(...ids) / selectionRemove(...ids) |
Change the selection. |
focusItem(id?) / see(id) |
Focus / scroll to an item. |
tagConfigure(tag, opts) |
Style a tag (e.g. a row colour). |
Plus the inherited widget methods — see Widget basics.
Events
Selection changes fire <<TreeviewSelect>>; bind <Double-1> for activation.
See also
- The file browser and todo examples
- Listbox