Tree view

TreeViewControl

Show folders, categories or a staff directory as a tree users expand, check and rearrange.

Overview

TreeViewControl is a Blazor tree view that shows nested items, such as folders or a staff directory, which users expand, select, check, rename and drag. Use it, rather than a tree grid, when each node is a name, not a row of columns; LoadChildren fetches a branch when it opens, and EnableVirtualization renders only the nodes in view. UseVb6TreeStyle draws the dotted lines of the classic Windows tree control.

Examples

#Staff directory with a node inspector

Browse the staff directory: type in the search box to find a person, click a node to read it on the right, and expand or collapse everything from code. VB6 lines switches to the classic connector lines, and the folder styles apply while it is on.

Staff Directory
Reservations
Hermione Ranger
Ron Measly
Ginny Measly

Selected in the directory

Name
Staff Directory
Kind
Group
Entries inside
3
Open
yes
Details
Current staff

#Check boxes: pick extras for a new hire

Check the extras for the new hire's onboarding order and the total follows. Checking a group checks everything in it, and a group with only some of its extras checked shows as partly checked, through AutoCheck; the buttons call CheckAllAsync.

Desk setup
Headset, $80
Second monitor, $210
Training
Spreadsheet basics, $65
Customer care workshop, $120
First aid course, $95
Transit pass, $120

Onboarding order for Sybil Treeline

Standard kit
$1,450
Headset
$80
Total
$1,530

Documentation

ParameterTypeDefaultDescription
NodesList<TreeNode>?nullRoot nodes; each carries its Children. A null list is replaced by an empty one on first use. Ids must be non-empty and unique across the tree, or the control throws.
SelectedNode / SelectedNodeChangedTreeNode?nullThe primary selected node, two-way. Setting it selects the node with that Id and clears the others unless AllowMultiSelect is on. Ignored while SelectedNodeIds is set, which then supplies it.
SelectedNodeIds / CheckedNodeIds / ExpandedNodeIdsIReadOnlyList<string>?nullId lists that drive selection, checks and expansion, each with a …Changed callback. Applied when the sequence changes; null leaves the node flags alone.
OnNodeClick / OnNodeDoubleClick / OnNodeActivated / OnNodeExpandEventCallback<TreeNode>—OnNodeClick follows a click, after the selection. OnNodeDoubleClick follows a double-click, and Enter when OnNodeActivated has no handler; OnNodeActivated is raised by Enter only. OnNodeExpand is raised when a single node becomes expanded, after any lazy load; ExpandAllAsync does not raise it.
ToggleOnNodeClickbooltrueA plain click on a parent expands or collapses it before selecting it; a Ctrl, Cmd or Shift click only selects. The expander arrow toggles regardless.
ShowIconsbooltrueDraws each node's IconCss (ExpandedIconCss while expanded). With the VB6 style a parent without its own icon gets a folder in FolderStyle and a leaf a spacer; the Standard style draws nothing for a node without IconCss.
FolderStyleTreeFolderStyleTreeFolderStyle.YellowYellow, Grey or None. Read only when the VB6 style is on; it picks the root modifier class and the folder icon.
UseVb6TreeStyleboolfalseDotted connector lines and plus/minus boxes, as in the Windows common control. A CssClass containing fx-treeview-vb6 turns it on too.
TreeIndentPixelsint16Indent per level in the VB6 and Outline styles. The Standard style without VB6 lines ignores it and indents 20px per level.
ShowCheckboxes / AutoCheckboolfalseA checkbox per node in the Standard display mode (Outline rows draw none, though aria-checked and Space still apply); Space toggles the focused one. AutoCheck cascades a check down to the children and sets each parent checked or indeterminate from its children.
AllowMultiSelectboolfalseCtrl-click toggles a node, Shift-click selects the visible range from the last node selected without Shift, Ctrl+A selects every visible node. Off, a click or Space selects one node.
Height / CssClassstring?nullHeight sizes the root with overflow:auto; CssClass is appended to the root element.
TabIndexint0The tabindex of the root element, the tree's only tab stop.
AriaLabelstring"Tree"The aria-label of the root element.
FocusOnSelectionbooltrueAfter a selection or a reveal the root element takes focus again, without scrolling. Turn off when the page must keep focus in another input.
DisplayModeTreeViewDisplayModeTreeViewDisplayMode.StandardStandard is the classic tree. Outline draws status circles and dots, a connector rail, the node's Caption, SecondaryText, SecondaryIcon and BadgeText, and a chevron on the right.
ShowSearchBoxboolfalseShows a search box above the tree whose text filters the nodes as you type. FilterText wins when both are set.
SearchPlaceholderstring"Search"Placeholder and aria-label of the search box.
SearchText / SearchTextChangedstring?nullThe search box text, two-way; it filters even while the box is hidden. A node stays visible when its Text contains the filter, ignoring case (current culture), or when a descendant does; the branches above a match are shown expanded whatever their IsExpanded. The children of a matching group are hidden unless they match too, and nodes cannot be expanded or collapsed while a filter is active. Whitespace only means no filter.
FilterTextstring?nullA filter set by the page. It takes precedence over the search box text and matches the same way.
EmptyFilterTextstring"No matches"Shown in a status region under the tree when the search box filter matches nothing. Only with ShowSearchBox: a host FilterText that matches nothing leaves the tree empty, as before.
AllowEditingboolfalseF2 or a double-click opens an inline rename with Save and Cancel buttons; Enter commits, Escape cancels, an empty name is refused. Not shown on this page.
NodeEditing / NodeEditCommitting / NodeEditedEventCallback<TreeNodeEditEventArgs>—Before the editor opens, before the new text is applied, and after it. Cancel vetoes the first two; Error on the second shows the message instead of committing.
AllowDragAndDropboolfalseNodes become draggable; dropping one on another moves it inside that node as its last child. Not shown on this page.
CanDropFunc<TreeNodeMoveEventArgs, bool>?nullAsked before NodeMoving; false refuses the move without raising it.
NodeMoving / NodeMovedEventCallback<TreeNodeMoveEventArgs>—Before and after a move, by drop or by MoveNodeAsync; Cancel on the first vetoes it.
EnableVirtualizationboolfalseRow windowing through Virtualize with four rows of overscan; every row is forced to ItemSize high.
ItemSizefloat32Row height in px, used for virtualization and for scrolling a revealed row into view. Below 20 the control throws.
LoadChildrenFunc<TreeNode, CancellationToken, Task<IReadOnlyList<TreeNode>>>?nullCalled the first time a node with HasUnloadedChildren expands, and for such nodes that start expanded; the result replaces its Children. A failure collapses the node and reports through Error.
NodeTemplateRenderFragment<TreeNode>?nullReplaces the node text; key presses inside it do not reach the tree.
NodeComparerIComparer<TreeNode>?nullSorts the siblings at every level.
NodesChangedEventCallback<List<TreeNode>>—Raised with the root list after a single node expands or collapses (not ExpandAllAsync or CollapseAllAsync), a committed rename, and AddNodeAsync, RemoveNodeAsync or MoveNodeAsync.
ErrorEventCallback<string>—Raised with the message of a failed lazy load, rename or move; the same message appears in an alert under the tree.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.