Class TreeView<T>
Hierarchical tree view with expandable branches. Branch objects are dynamically determined
when expanded using a user defined
ITreeBuilder<T>
Inheritance
System.Object
TreeView<T>
Implements
System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Assembly: Terminal.Gui.dll
Syntax
public class TreeView<T> : View, IDisposable, ISupportInitializeNotification, ISupportInitialize, ITreeView where T : class
Type Parameters
Constructors
TreeView()
Declaration
TreeView(ITreeBuilder<T>)
Declaration
public TreeView(ITreeBuilder<T> builder)
Parameters
Fields
NoBuilderError
Error message to display when the control is not properly initialized at draw time
(nodes added but no tree builder set)
Declaration
public static ustring NoBuilderError
Field Value
Type |
Description |
NStack.ustring |
|
Properties
AllowLetterBasedNavigation
True makes a letter key press navigate to the next visible branch that begins with
that letter/digit
Declaration
public bool AllowLetterBasedNavigation { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
AspectGetter
Returns the string representation of model objects hosted in the tree. Default
implementation is to call System.Object.ToString()
Declaration
public AspectGetterDelegate<T> AspectGetter { get; set; }
Property Value
ContentHeight
The current number of rows in the tree (ignoring the controls bounds)
Declaration
public int ContentHeight { get; }
Property Value
Type |
Description |
System.Int32 |
|
MultiSelect
True to allow multiple objects to be selected at once
Declaration
public bool MultiSelect { get; set; }
Property Value
Type |
Description |
System.Boolean |
|
ObjectActivationKey
Declaration
public Key ObjectActivationKey { get; set; }
Property Value
Objects
The root objects in the tree, note that this collection is of root objects only
Declaration
public IEnumerable<T> Objects { get; }
Property Value
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
The amount of tree view that has been scrolled to the right (horizontally)
Declaration
public int ScrollOffsetHorizontal { get; set; }
Property Value
Type |
Description |
System.Int32 |
|
The amount of tree view that has been scrolled off the top of the screen (by the user
scrolling down)
Declaration
public int ScrollOffsetVertical { get; set; }
Property Value
Type |
Description |
System.Int32 |
|
SelectedObject
The currently selected object in the tree. When
MultiSelect is true this
is the object at which the cursor is at
Declaration
public T SelectedObject { get; set; }
Property Value
Style
Contains options for changing how the tree is rendered
Declaration
public TreeStyle Style { get; set; }
Property Value
TreeBuilder
Determines how sub branches of the tree are dynamically built at runtime as the user
expands root nodes
Declaration
public ITreeBuilder<T> TreeBuilder { get; set; }
Property Value
Methods
AddObject(T)
Adds a new root level object unless it is already a root of the tree
Declaration
public void AddObject(T o)
Parameters
Type |
Name |
Description |
T |
o |
|
AddObjects(IEnumerable<T>)
Adds many new root level objects. Objects that are already root objects are ignored
Declaration
public void AddObjects(IEnumerable<T> collection)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
collection |
Objects to add as new root level objects |
AdjustSelection(Int32, Boolean)
The number of screen lines to move the currently selected object by. Supports negative
offset
. Each branch occupies 1 line on screen
Declaration
public void AdjustSelection(int offset, bool expandSelection = false)
Parameters
Type |
Name |
Description |
System.Int32 |
offset |
Positive to move the selection down the screen, negative to move it up |
System.Boolean |
expandSelection |
True to expand the selection (assuming
MultiSelect is enabled). False to replace |
AdjustSelectionToBranchEnd()
Moves the selection to the last child in the currently selected level
Declaration
public void AdjustSelectionToBranchEnd()
AdjustSelectionToBranchStart()
Moves the selection to the first child in the currently selected level
Declaration
public void AdjustSelectionToBranchStart()
CanExpand(T)
Returns true if the given object o
is exposed in the tree and can be
expanded otherwise false
Declaration
public bool CanExpand(T o)
Parameters
Type |
Name |
Description |
T |
o |
|
Returns
Type |
Description |
System.Boolean |
|
ClearObjects()
Declaration
public void ClearObjects()
Collapse(T)
Collapses the supplied object if it is currently expanded
Declaration
public void Collapse(T toCollapse)
Parameters
Type |
Name |
Description |
T |
toCollapse |
The object to collapse |
CollapseAll()
Collapses all root nodes in the tree
Declaration
public void CollapseAll()
CollapseAll(T)
Collapses the supplied object if it is currently expanded. Also collapses all children
branches (this will only become apparent when/if the user expands it again)
Declaration
public void CollapseAll(T toCollapse)
Parameters
Type |
Name |
Description |
T |
toCollapse |
The object to collapse |
CollapseImpl(T, Boolean)
Declaration
protected void CollapseImpl(T toCollapse, bool all)
Parameters
Type |
Name |
Description |
T |
toCollapse |
|
System.Boolean |
all |
|
CursorLeft(Boolean)
Determines systems behaviour when the left arrow key is pressed. Default behaviour is
to collapse the current tree node if possible otherwise changes selection to current
branches parent
Declaration
protected virtual void CursorLeft(bool ctrl)
Parameters
Type |
Name |
Description |
System.Boolean |
ctrl |
|
EnsureVisible(T)
Adjusts the
ScrollOffsetVertical to ensure the given
model
is visible. Has no effect if already visible
Declaration
public void EnsureVisible(T model)
Parameters
Type |
Name |
Description |
T |
model |
|
Expand(T)
Expands the supplied object if it is contained in the tree (either as a root object or
as an exposed branch object)
Declaration
public void Expand(T toExpand)
Parameters
Type |
Name |
Description |
T |
toExpand |
The object to expand |
ExpandAll()
Fully expands all nodes in the tree, if the tree is very big and built dynamically this
may take a while (e.g. for file system)
Declaration
ExpandAll(T)
Expands the supplied object and all child objects
Declaration
public void ExpandAll(T toExpand)
Parameters
Type |
Name |
Description |
T |
toExpand |
The object to expand |
GetAllSelectedObjects()
Declaration
public IEnumerable<T> GetAllSelectedObjects()
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
GetChildren(T)
Returns the currently expanded children of the passed object. Returns an empty
collection if the branch is not exposed or not expanded
Declaration
public IEnumerable<T> GetChildren(T o)
Parameters
Type |
Name |
Description |
T |
o |
An object in the tree |
Returns
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
GetContentWidth(Boolean)
Returns the maximum width line in the tree including prefix and expansion symbols
Declaration
public int GetContentWidth(bool visible)
Parameters
Type |
Name |
Description |
System.Boolean |
visible |
True to consider only rows currently visible (based on window
bounds and ScrollOffsetVertical. False to calculate the width of
every exposed branch in the tree |
Returns
Type |
Description |
System.Int32 |
|
GetParent(T)
Returns the parent object of o
in the tree. Returns null if
the object is not exposed in the tree
Declaration
Parameters
Type |
Name |
Description |
T |
o |
An object in the tree |
Returns
Returns the index of the object
o
if it is currently exposed (it's
parent(s) have been expanded). This can be used with
ScrollOffsetVertical
and
SetNeedsDisplay() to scroll to a specific object
Declaration
public int GetScrollOffsetOf(T o)
Parameters
Type |
Name |
Description |
T |
o |
An object that appears in your tree and is currently exposed |
Returns
Type |
Description |
System.Int32 |
The index the object was found at or -1 if it is not currently revealed or
not in the tree at all |
GoTo(T)
Changes the
SelectedObject to
toSelect
and scrolls to ensure
it is visible. Has no effect if
toSelect
is not exposed in the tree (e.g.
its parents are collapsed)
Declaration
public void GoTo(T toSelect)
Parameters
Type |
Name |
Description |
T |
toSelect |
|
GoToEnd()
Changes the
SelectedObject to the last object in the tree and scrolls so
that it is visible
Declaration
GoToFirst()
Declaration
InvalidateLineMap()
Clears any cached results of Terminal.Gui.TreeView`1.BuildLineMap
Declaration
protected void InvalidateLineMap()
IsExpanded(T)
Returns true if the given object o
is exposed in the tree and
expanded otherwise false
Declaration
public bool IsExpanded(T o)
Parameters
Type |
Name |
Description |
T |
o |
|
Returns
Type |
Description |
System.Boolean |
|
IsSelected(T)
Declaration
public bool IsSelected(T model)
Parameters
Type |
Name |
Description |
T |
model |
|
Returns
Type |
Description |
System.Boolean |
|
MouseEvent(MouseEvent)
Method invoked when a mouse event is generated
Declaration
public override bool MouseEvent(MouseEvent me)
Parameters
Returns
Type |
Description |
System.Boolean |
true , if the event was handled, false otherwise. |
Overrides
OnObjectActivated(ObjectActivatedEventArgs<T>)
Declaration
protected virtual void OnObjectActivated(ObjectActivatedEventArgs<T> e)
Parameters
OnSelectionChanged(SelectionChangedEventArgs<T>)
Raises the SelectionChanged event
Declaration
protected virtual void OnSelectionChanged(SelectionChangedEventArgs<T> e)
Parameters
PositionCursor()
Positions the cursor at the start of the selected objects line (if visible)
Declaration
public override void PositionCursor()
Overrides
ProcessKey(KeyEvent)
If the view is focused, gives the view a
chance to process the keystroke.
Declaration
public override bool ProcessKey(KeyEvent keyEvent)
Parameters
Type |
Name |
Description |
KeyEvent |
keyEvent |
Contains the details about the key that produced the event. |
Returns
Type |
Description |
System.Boolean |
|
Overrides
RebuildTree()
Rebuilds the tree structure for all exposed objects starting with the root objects.
Call this method when you know there are changes to the tree but don't know which
objects have changed (otherwise use
RefreshObject(T, Boolean))
Declaration
public void RebuildTree()
Redraw(Rect)
Redraws this view and its subviews; only redraws the views that have been flagged for a re-display.
Declaration
public override void Redraw(Rect bounds)
Parameters
Type |
Name |
Description |
Rect |
bounds |
The bounds (view-relative region) to redraw. |
Overrides
RefreshObject(T, Boolean)
Refreshes the state of the object o
in the tree. This will
recompute children, string representation etc
Declaration
public void RefreshObject(T o, bool startAtTop = false)
Parameters
Type |
Name |
Description |
T |
o |
|
System.Boolean |
startAtTop |
True to also refresh all ancestors of the objects branch
(starting with the root). False to refresh only the passed node |
Remove(T)
Removes the given root object from the tree
Declaration
Parameters
Type |
Name |
Description |
T |
o |
|
SelectAll()
Selects all objects in the tree when
MultiSelect is enabled otherwise
does nothing
Declaration
Events
ObjectActivated
This event is raised when an object is activated e.g. by double clicking or
pressing
ObjectActivationKey
Declaration
public event Action<ObjectActivatedEventArgs<T>> ObjectActivated
Event Type
SelectionChanged
Declaration
public event EventHandler<SelectionChangedEventArgs<T>> SelectionChanged
Event Type
Implements
System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize