HypernovaDesktop Components · docs
Binarymission
WinForms › Tree List View › BinaryTreeListViewNodesCollection

BinaryTreeListViewNodesCollection

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.TreeControls

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
BinaryTreeListViewNodesCollectionCreates an empty collection of children for a node.
Properties
CountGets the number of nodes in the collection – the node's children, not counting their own children.
IsReadOnlyGets whether the collection is read-only.
ItemGets the node at a position among the siblings.
Methods
AddAdds a node you have created, as the last child.
AddCreates a node with a text in its tree cell, adds it as the last child, and returns it.
AddCreates a node from one value per column, adds it as the last child, and returns it.
ClearRemoves every node from the collection.
ContainsReturns whether a node is one of the nodes in this collection.
CopyToNot supported: always throws. Enumerate the collection, or use LINQ's ToArray, instead.
GetEnumeratorReturns an enumerator over the nodes, in order.
IndexOfReturns the position of a node among the siblings.
InsertInserts a node you have created at a position among the siblings.
RemoveRemoves a node, with everything beneath it, from the collection.
RemoveAtRemoves the node at a position among the siblings, with everything beneath it.

Constructors

BinaryTreeListViewNodesCollection

public BinaryTreeListViewNodesCollection(BinaryTreeListViewNode collectionOwnerNode)

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

public int Count

Gets the number of nodes in the collection – the node's children, not counting their own children.

IsReadOnly

public bool IsReadOnly

Gets whether the collection is read-only.

Value
Always false.

Item

public BinaryTreeListViewNode this[int theIndex]

Gets the node at a position among the siblings.

Parameters
theIndex
The zero-based position.
Returns

The node at that position.

Exceptions
System.ArgumentOutOfRangeException
theIndex is not a position in the collection.
System.Exception
A node is set.
Remarks

The collection cannot be changed through the indexer: setting a node throws. Use Insert and RemoveAt.

Methods

Add

public void Add(BinaryTreeListViewNode aNode)

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

public BinaryTreeListViewNode Add(string stringValue)

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

public BinaryTreeListViewNode Add(params object[] cellValues)

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 BinaryTreeListViewCellInfo among them sets the node's image settings and is shown as its BinaryTreeListViewCellInfo.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

public void 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

public bool Contains(BinaryTreeListViewNode theNode)

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

public void CopyTo(BinaryTreeListViewNode[] arrayOfItems, int index)

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

public IEnumerator<BinaryTreeListViewNode> 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

public int IndexOf(BinaryTreeListViewNode theItem)

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

public void Insert(int index, BinaryTreeListViewNode nodeItem)

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.ArgumentOutOfRangeException
index is less than 0 or greater than Count.
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

public bool Remove(BinaryTreeListViewNode nodeItem)

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

public void RemoveAt(int index)

Removes the node at a position among the siblings, with everything beneath it.

Parameters
index
The zero-based position of the node.
Exceptions
System.ArgumentOutOfRangeException
index is 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.