BinaryTreeListViewNodesCollection
The children of a node, or the top-level nodes of a BinaryTreeListView: the
collection through which the tree is built.
public class BinaryTreeListViewNodesCollection : IList<BinaryTreeListViewNode>, System.Collections.IList
Inherits from / implements: IList<BinaryTreeListViewNode>, System.Collections.IList
Remarks
Get one from BinaryTreeListView.Nodes or BinaryTreeListViewNode.Nodes.
Adding a node here puts it in the tree, and on show when its parent is open; the control keeps the
grid's rows in step. The order of the collection is the order of the siblings on screen.
The usual way to add a node is Add(), which takes one value per column
and returns the new node.
Examples
// Columns: Item (the tree column), Quantity, Unit cost.
BinaryTreeListViewNode bike = parts.Nodes.Add("Road bike", 1, 1480.00m);
BinaryTreeListViewNode wheels = bike.Nodes.Add("Wheelset", 1, 420.00m);
wheels.Nodes.Add("Rim", 2, 95.00m);
wheels.Nodes.Add("Spoke", 48, 1.20m);
bike.Nodes.Add("Frame", 1, 610.00m);
foreach (BinaryTreeListViewNode part in bike.Nodes)
Console.WriteLine(part.Cells[0].Value + " x " + part.Cells[1].Value);Members at a glance
| Constructors | |
|---|---|
BinaryTreeListViewNodesCollection | Creates an empty collection of children for a node. |
| Properties | |
Count | Gets the number of nodes in the collection – the node's children, not counting their own children. |
IsReadOnly | Gets whether the collection is read-only. |
Item | Gets the node at a position among the siblings. |
| Methods | |
Add | Adds a node you have created, as the last child. |
Add | Creates a node with a text in its tree cell, adds it as the last child, and returns it. |
Add | Creates a node from one value per column, adds it as the last child, and returns it. |
Clear | Removes every node from the collection. |
Contains | Returns whether a node is one of the nodes in this collection. |
CopyTo | Not supported: always throws. Enumerate the collection, or use LINQ's ToArray, instead. |
GetEnumerator | Returns an enumerator over the nodes, in order. |
IndexOf | Returns the position of a node among the siblings. |
Insert | Inserts a node you have created at a position among the siblings. |
Remove | Removes a node, with everything beneath it, from the collection. |
RemoveAt | Removes the node at a position among the siblings, with everything beneath it. |
Constructors
BinaryTreeListViewNodesCollection
Creates an empty collection of children for a node.
Parameters
collectionOwnerNode- The node whose children the collection holds.
Remarks
A node creates its own collection when BinaryTreeListViewNode.Nodes is first read, so
there is rarely a reason to call this.
Properties
Count
Gets the number of nodes in the collection – the node's children, not counting their own children.
IsReadOnly
Gets whether the collection is read-only.
- Value
- Always
false.
Item
Gets the node at a position among the siblings.
Parameters
theIndex- The zero-based position.
Returns
The node at that position.
Exceptions
System.ArgumentOutOfRangeExceptiontheIndexis not a position in the collection.System.Exception- A node is set.
Remarks
Methods
Add
Adds a node you have created, as the last child.
Parameters
aNode- The node to add, with any children it already has. It must not be in another collection.
Remarks
The node takes its cells from the control's columns. It is on show at once when the collection is the control's top-level nodes, or its parent is open and on show.
Add
Creates a node with a text in its tree cell, adds it as the last child, and returns it.
Parameters
stringValue- The text for the node's cell in the tree column. The other cells are left empty.
Returns
The new node, to set further values on or to add children to.
Remarks
This overload is chosen whenever a single string is passed. The collection must belong to a node
in a tree, or be the control's top-level nodes; otherwise it throws a
NullReferenceException.
Example
BinaryTreeListViewNode region = sales.Nodes.Add("North West");
region.Cells["Target"].Value = 250000m;Add
Creates a node from one value per column, adds it as the last child, and returns it.
Parameters
cellValues- The node's cell values, in column order – the first value goes in the first
column, whichever column is the tree column. Fewer values than columns leave the remaining cells
empty. A
BinaryTreeListViewCellInfoamong them sets the node's image settings and is shown as itsBinaryTreeListViewCellInfo.Text.
Returns
The new node, to set further values on or to add children to.
Exceptions
System.ArgumentOutOfRangeException- More values are given than the control has columns.
System.NullReferenceException- The collection's node is not in a tree, or the value
for the tree column is
null.
Remarks
Add the control's columns first. The collection must belong to a node in a tree, or be the
control's top-level nodes: build a branch from the top down. The value for the tree column must not
be null.
The node is on show at once when the collection is the control's top-level nodes, or its parent is open and on show. A new node is closed.
Example
// Columns: Customer (the tree column), Order date, Total, Status.
BinaryTreeListViewNode customer = orders.Nodes.Add("Hartley & Sons", null, 1840.50m, "Open");
customer.Nodes.Add("SO-10422", new DateTime(2026, 9, 14), 1220.00m, "Shipped");
customer.Nodes.Add("SO-10457", new DateTime(2026, 10, 3), 620.50m, "Awaiting stock");
customer.Expand();See also
Clear
Removes every node from the collection.
Remarks
Rows already on show stay in the grid. To empty the whole control, call
BinaryTreeListView.ClearAllNodes instead, which removes the rows as well.
Contains
Returns whether a node is one of the nodes in this collection.
Parameters
theNode- The node to look for.
Returns
true when the node is in this collection. Nodes further down the tree are
not searched.
CopyTo
Not supported: always throws. Enumerate the collection, or use LINQ's ToArray, instead.
Parameters
arrayOfItems- Not used.
index- Not used.
Exceptions
System.Exception- Always.
GetEnumerator
Returns an enumerator over the nodes, in order.
Returns
An enumerator over the nodes in the collection.
Remarks
Do not add or remove nodes in the collection while enumerating it.
IndexOf
Returns the position of a node among the siblings.
Parameters
theItem- The node to look for.
Returns
The zero-based position of the node, or -1 when it is not in the collection.
Insert
Inserts a node you have created at a position among the siblings.
Parameters
index- The zero-based position the node is to take, from 0 to
Count. nodeItem- The node to insert. It must not be in another collection.
Exceptions
System.ArgumentOutOfRangeExceptionindexis less than 0 or greater thanCount.
Remarks
The node is shown in its place at once when the collection is the control's top-level nodes, or its parent is open and on show.
Remove
Removes a node, with everything beneath it, from the collection.
Parameters
nodeItem- The node to remove.
Returns
true when the node was in the collection and has been removed.
Remarks
The node leaves the tree, but a row already on show stays in the grid, with the rows of any
open nodes beneath it. To remove a child node from view as well, close its parent first and open
it again afterwards; for a top-level node, close it and then remove its row with
tree.Rows.Remove(node). BinaryTreeListView.ClearAllNodes removes everything,
rows included.
See also
RemoveAt
Removes the node at a position among the siblings, with everything beneath it.
Parameters
index- The zero-based position of the node.
Exceptions
System.ArgumentOutOfRangeExceptionindexis not a position in the collection.
Remarks
The node leaves the tree, but a row already on show stays in the grid, with the rows of any
open nodes beneath it. To remove a child node from view as well, close its parent first and open
it again afterwards; for a top-level node, close it and then remove its row with
tree.Rows.Remove(node). BinaryTreeListView.ClearAllNodes removes everything,
rows included.