BinaryTreeListViewNode
A node of a BinaryTreeListView: one row of the grid, with its own child nodes, which
the control shows indented beneath it when it is open.
public class BinaryTreeListViewNode : DataGridViewRow
Inherits from / implements: DataGridViewRow
Remarks
A node is a DataGridViewRow, so its values are in Cells, one per
column, and its look in DefaultCellStyle and
Height. Keep the object a row stands for in
Tag.
Creating nodes
Nodes are usually created by the collections: tree.Nodes.Add(values) for a top-level
node and node.Nodes.Add(values) for a child, each taking one value per column and returning
the new node. A node made with the constructor is added with
BinaryTreeListViewNodesCollection.Add(). The tree builds the
rows; never add a node to the grid's own rows.
Open and closed
A node starts closed. Expand() and Collapse() open and close it,
raising the control's expanding and collapsing events; while it is closed its descendants are not
in the grid at all.
Two indexes
Index is the node's position among its siblings, and stays the same however the
tree is opened and closed. NodeIndex is its row in the grid as shown now – the index
the grid's own events and methods use – and is -1 while the node is not on show.
Examples
// Columns: Name (the tree column), Size, Modified.
BinaryTreeListViewNode docs = files.Nodes.Add("Documents", "", new DateTime(2026, 9, 30));
BinaryTreeListViewNode invoices = docs.Nodes.Add("Invoices", "", new DateTime(2026, 10, 2));
invoices.Nodes.Add("INV-2026-0412.pdf", "84 KB", new DateTime(2026, 10, 1));
invoices.Nodes.Add("INV-2026-0413.pdf", "79 KB", new DateTime(2026, 10, 2));
docs.Expand();
invoices.Expand();
// Walk up from a node to build its path; the hidden root above the top level has no parent.
BinaryTreeListViewNode node = invoices.Nodes[1];
string path = (string)node.Cells[0].Value;
for (BinaryTreeListViewNode parent = node.ParentNode; parent.ParentNode != null; parent = parent.ParentNode)
path = parent.Cells[0].Value + "\\" + path; // Documents\Invoices\INV-2026-0413.pdfSee also
Members at a glance
| Constructors | |
|---|---|
BinaryTreeListViewNode | Creates a closed node with no cells, no children and no parent. |
| Properties | |
BinaryTreeListViewCellInfo | Gets or sets the image settings of this node's tree cell, as one object. |
CellInfoCheckStatus | Gets or sets whether the node shows a check box or a radio button, and whether it is ticked. |
Cells | Gets the node's cells, one per column of the control. |
CollapseImage | Gets or sets the image drawn as this node's collapse glyph while it is open. |
ExpandImage | Gets or sets the image drawn as this node's expand glyph while it is closed. |
HasChildren | Gets whether the node has any child nodes. |
Image | Gets or sets the image drawn beside this node's text. |
Index | Gets the node's position among its siblings. |
IsFirstSibling | Gets whether the node is the first child of its parent (or the first top-level node). |
IsLastSibling | Gets whether the node is the last child of its parent (or the last top-level node). |
NodeIndex | Gets the node's row in the grid as it is shown now. |
Nodes | Gets the node's children. |
ParentNode | Gets the node this node is a child of. |
ShowNodeImage | Gets or sets whether the node shows its image. |
| Methods | |
Clone | Creates a copy of this node's row for the same control, as Clone does. |
CloneWithCellsData | Creates a copy of this node with its cell values, ready to add to a tree. |
Collapse | Closes the node, taking its descendants off the grid. |
Collapse | Closes the node and, if asked, every node beneath it. |
CreateCellsInstance | Creates the node's cell collection, and watches it so that the node finds its cell in the tree column as the cells are added. |
Expand | Opens the node, showing its children. |
Expand | Opens the node and, if asked, every node beneath it. |
ToString | Returns the node's cell values as one string, each followed by a space. |
Constructors
BinaryTreeListViewNode
Creates a closed node with no cells, no children and no parent.
Remarks
Add it to a tree with BinaryTreeListViewNodesCollection.Add();
it takes its cells from the control's columns then. Calling Expand() before adding it
makes it open as soon as it is shown.
Properties
BinaryTreeListViewCellInfo
Gets or sets the image settings of this node's tree cell, as one object.
- Value
- The
BinaryTreeListViewCellInfolast set through this property, ornull, the default.
Remarks
Setting it gives the node the info's BinaryTreeListViewCellInfo.Image
and BinaryTreeListViewCellInfo.ShowImage, and repaints the control. The text
shown in the cell is the cell's value, not the info's
BinaryTreeListViewCellInfo.Text; change Cells to change it.
Set it once the node is in a tree; a node that is not throws a
NullReferenceException.
See also
CellInfoCheckStatus
Gets or sets whether the node shows a check box or a radio button, and whether it is ticked.
- Value
CellInfoCheckStatus.Noneby default: no check box, and the node's image is shown.
Remarks
Check boxes and radio buttons are drawn only on nodes that have no children, in place of the image. The user changes them by clicking: a check box toggles; a radio button is selected and its siblings' radio buttons are cleared (a radio button with no siblings toggles). Read this property to find out what the user chose.
Setting it does not repaint the node; call
DataGridView.InvalidateRow with NodeIndex if the node is on show.
BinaryTreeListView.SetUpNodeControlType sets it on every node at once.
Example
// Tick a permission and show the change.
BinaryTreeListViewNode canExport = permissions.Nodes[2].Nodes[0];
canExport.CellInfoCheckStatus = CellInfoCheckStatus.CheckBoxCheckedNormal;
if (canExport.NodeIndex >= 0)
permissions.InvalidateRow(canExport.NodeIndex);See also
Cells
Gets the node's cells, one per column of the control.
- Value
- The cells, in column order. For a node that has been added to a tree but is not on show, they are
created from the control's columns when first read.
nullfor a node that has not been added to a tree.
Example
BinaryTreeListViewNode node = plan.CurrentNode;
node.Cells["Owner"].Value = "Tom Hughes";
decimal done = Convert.ToDecimal(node.Cells["Done"].Value);CollapseImage
Gets or sets the image drawn as this node's collapse glyph while it is open.
- Value
null, the default, to use the control'sBinaryTreeListView.CollapseImage.
See also
ExpandImage
Gets or sets the image drawn as this node's expand glyph while it is closed.
- Value
null, the default, to use the control'sBinaryTreeListView.ExpandImage.
Remarks
A glyph image is used only when an expand image and a collapse image are both available – this node's or the control's; otherwise the system glyph is drawn. It is drawn 10 by 10 logical pixels.
See also
HasChildren
Gets whether the node has any child nodes.
- Value
truewhenNodesholds at least one node, whether or not this node is open.
Image
Gets or sets the image drawn beside this node's text.
- Value
- When read: the control's
BinaryTreeListView.NodeImageif that is set, otherwise the image set on this node, ornull.
Remarks
An image set here is the one drawn for this node, in preference to the control's
BinaryTreeListView.NodeImage. It is drawn at its own pixel size, between the expand
glyph and the text, unless the node has a check box or radio button or
ShowNodeImage is off.
Set it once the node is in a tree and its tree cell has a value; reading or setting it on a
node that is not in a tree throws a NullReferenceException.
Example
BinaryTreeListViewNode report = folder.Nodes.Add("Q3 report.xlsx", "212 KB", DateTime.Today);
report.Image = SystemHelper.GetFileIcon("Q3 report.xlsx", SystemHelper.EnumIconSize.Small, false).ToBitmap();See also
Index
Gets the node's position among its siblings.
- Value
- The zero-based index of the node in its parent's
Nodes, or in the control's top-level nodes.
Exceptions
System.NullReferenceException- The node is not in a collection.
Remarks
It does not depend on which nodes are open. For the node's row in the grid, use
NodeIndex.
See also
IsFirstSibling
Gets whether the node is the first child of its parent (or the first top-level node).
- Value
truewhenIndexis 0.
Exceptions
System.NullReferenceException- The node is not in a collection.
IsLastSibling
Gets whether the node is the last child of its parent (or the last top-level node).
- Value
truefor the last of its siblings, and for a node that has no parent.
NodeIndex
Gets the node's row in the grid as it is shown now.
- Value
- The zero-based row index, the same index the grid's own events and methods use; -1 while the node is not on show – inside a closed node, or not yet added to a tree.
Remarks
It changes as nodes above it open, close and are sorted. For the node's place among its siblings,
which does not, use Index.
See also
Nodes
Gets the node's children.
- Value
- The node's child collection, created the first time it is read; never
null.
Remarks
Add children with BinaryTreeListViewNodesCollection.Add(), one value per column.
A child is on show while this node is open and on show itself.
See also
ParentNode
Gets the node this node is a child of.
- Value
- The parent node;
nullfor a node that has not been added to a tree. For a top-level node it is the control's hidden root node, which is never shown and has no parent of its own.
Remarks
To tell whether a node is at the top level, test tree.Nodes.Contains(node).
ShowNodeImage
Gets or sets whether the node shows its image.
- Value
trueby default.
Remarks
Setting it repaints the node if it is on show. Set it once the node is in a tree and its tree cell
has a value; otherwise it throws a NullReferenceException.
See also
Methods
Clone
Creates a copy of this node's row for the same control, as Clone does.
Returns
A new BinaryTreeListViewNode, not in any tree, with no children.
Remarks
For a copy that carries the cell values, check state and glyph images, use
CloneWithCellsData.
CloneWithCellsData
Creates a copy of this node with its cell values, ready to add to a tree.
Returns
A new, closed BinaryTreeListViewNode with the same cell values,
CellInfoCheckStatus, ExpandImage, CollapseImage and
BinaryTreeListViewCellInfo. It has no children and is not in any tree.
Remarks
The children are not copied; copy them one by one if the whole branch is wanted. An image set
through Image is not copied; one set through BinaryTreeListViewCellInfo
is.
Example
// Duplicate a task under the same parent.
BinaryTreeListViewNode copy = task.CloneWithCellsData();
task.ParentNode.Nodes.Add(copy);
copy.Cells[0].Value = task.Cells[0].Value + " (copy)";Collapse
Closes the node, taking its descendants off the grid.
Returns
true when the node was closed; false when it was already
closed or a BinaryTreeListView.BinaryTreeListViewNodeCollapsing handler kept it open.
Exceptions
System.NullReferenceException- The node is not in a tree.
Remarks
Its children keep their own open state for when it is opened again.
See also
Collapse
Closes the node and, if asked, every node beneath it.
Parameters
performDeepCollapsetrueto close every descendant as well, so that the branch reopens one level at a time.
Returns
Always true.
Exceptions
System.NullReferenceException- The node is not in a tree.
See also
CreateCellsInstance
Creates the node's cell collection, and watches it so that the node finds its cell in the tree column as the cells are added.
Returns
The new cell collection.
Expand
Opens the node, showing its children.
Returns
true when the node was opened, or was marked to open; false
when it was already open or a BinaryTreeListView.BinaryTreeListViewNodeExpanding handler
kept it closed.
Remarks
For a node that has not been added to a tree, it marks the node to be open as soon as it is shown.
Open a node only when its parent is open: the children of a node whose parent is closed are
placed at the top of the grid. Expand() opens a whole branch from the top
down.
Example
BinaryTreeListViewNode europe = sales.Nodes.Add("Europe", 1240000m);
europe.Nodes.Add("United Kingdom", 610000m);
europe.Nodes.Add("Germany", 630000m);
europe.Expand();See also
Expand
Opens the node and, if asked, every node beneath it.
Parameters
performDeepExpansiontrueto open every descendant as well, from the top down.
Returns
Always true.
Remarks
For a node that has not been added to a tree, it marks only this node to be open when it is shown.
See also
ToString
Returns the node's cell values as one string, each followed by a space.
Returns
The values of the cells that have one, in column order; an empty string when the node has no cells.