Table of Contents

Class ExTreeNodeCollection

Namespace
ExControls.Collections
Assembly
ExControls.dll

Represents a collection of tree nodes that also remembers hidden nodes; the wrapped TreeNodeCollection contains only the visible ones.

public class ExTreeNodeCollection : IList, ICollection, IReadOnlyList<TreeNode>, IReadOnlyCollection<TreeNode>, IEnumerable<TreeNode>, IEnumerable
Inheritance
ExTreeNodeCollection
Implements
Inherited Members
Extension Methods

Constructors

ExTreeNodeCollection(TreeNodeCollection)

Initializes a new instance of the ExTreeNodeCollection class.

public ExTreeNodeCollection(TreeNodeCollection nodes)

Parameters

nodes TreeNodeCollection

The collection that holds the visible nodes; its current nodes become the content of this collection.

Properties

Count

Gets the number of elements contained in the ICollection.

public int Count { get; }

Property Value

int

The number of elements contained in the ICollection.

IsFixedSize

Gets a value indicating whether the IList has a fixed size.

public virtual bool IsFixedSize { get; }

Property Value

bool

true if the IList has a fixed size; otherwise, false.

IsReadOnly

Gets a value indicating whether the IList is read-only.

public virtual bool IsReadOnly { get; }

Property Value

bool

true if the IList is read-only; otherwise, false.

IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

public bool IsSynchronized { get; }

Property Value

bool

true if access to the ICollection is synchronized (thread safe); otherwise, false.

this[int]

Gets or sets the element at the specified index.

public virtual TreeNode this[int index] { get; set; }

Parameters

index int

The zero-based index of the element to get or set.

Property Value

TreeNode

The element at the specified index.

Exceptions

ArgumentOutOfRangeException

index is not a valid index in the IList.

NotSupportedException

The property is set and the IList is read-only.

this[string]

Gets the visible tree node with the specified name, or null if there is none.

public virtual TreeNode? this[string key] { get; }

Parameters

key string

The name of the tree node to retrieve.

Property Value

TreeNode

SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

public object SyncRoot { get; }

Property Value

object

An object that can be used to synchronize access to the ICollection.

Methods

Add(object?)

Adds an item to the IList.

public virtual int Add(object? value)

Parameters

value object

The object to add to the IList.

Returns

int

The position into which the new element was inserted, or -1 to indicate that the item was not inserted into the collection.

Exceptions

NotSupportedException

The IList is read-only. -or- The IList has a fixed size.

Add(string)

Adds a new tree node with the specified label text to the end of the current tree node collection.

public virtual TreeNode Add(string text)

Parameters

text string

The label text displayed by the TreeNode.

Returns

TreeNode

A TreeNode that represents the tree node being added to the collection.

Add(string, string)

Creates a new tree node with the specified key and text, and adds it to the collection.

public virtual TreeNode Add(string key, string text)

Parameters

key string

The name of the tree node.

text string

The text to display in the tree node.

Returns

TreeNode

The TreeNode that was added to the collection.

Add(string, string, int)

Creates a tree node with the specified key, text, and image, and adds it to the collection.

public virtual TreeNode Add(string key, string text, int imageIndex)

Parameters

key string

The name of the tree node.

text string

The text to display in the tree node.

imageIndex int

The index of the image to display in the tree node.

Returns

TreeNode

The TreeNode that was added to the collection.

Add(string, string, int, int)

Creates a tree node with the specified key, text, and images, and adds it to the collection.

public virtual TreeNode Add(string key, string text, int imageIndex, int selectedImageIndex)

Parameters

key string

The name of the tree node.

text string

The text to display in the tree node.

imageIndex int

The index of the image to display in the tree node.

selectedImageIndex int

The index of the image to be displayed in the tree node when it is in a selected state.

Returns

TreeNode

The tree node that was added to the collection.

Add(string, string, string)

Creates a tree node with the specified key, text, and image, and adds it to the collection.

public virtual TreeNode Add(string key, string text, string imageKey)

Parameters

key string

The name of the tree node.

text string

The text to display in the tree node.

imageKey string

The image to display in the tree node.

Returns

TreeNode

The TreeNode that was added to the collection.

Add(string, string, string, string)

Creates a tree node with the specified key, text, and images, and adds it to the collection.

public virtual TreeNode Add(string key, string text, string imageKey, string selectedImageKey)

Parameters

key string

The name of the tree node.

text string

The text to display in the tree node.

imageKey string

The key of the image to display in the tree node.

selectedImageKey string

The key of the image to display when the node is in a selected state.

Returns

TreeNode

The TreeNode that was added to the collection.

Add(TreeNode)

Adds a previously created tree node to the end of the tree node collection.

public virtual int Add(TreeNode node)

Parameters

node TreeNode

The TreeNode to add to the collection.

Returns

int

The zero-based index value of the TreeNode added to the tree node collection.

Exceptions

ArgumentException

The node is currently assigned to another TreeView.

AddRange(TreeNode[])

Adds an array of previously created tree nodes to the collection.

public virtual void AddRange(TreeNode[] nodes)

Parameters

nodes TreeNode[]

An array of TreeNode objects representing the tree nodes to add to the collection.

Exceptions

ArgumentNullException

nodes is null.

ArgumentException

nodes is the child of another TreeView.

Clear()

Removes all tree nodes from the collection.

public virtual void Clear()

Clear(bool)

Removes all tree nodes from the collection.

public virtual void Clear(bool recursive)

Parameters

recursive bool

true to clear also the child nodes of the removed nodes

Contains(TreeNode, bool)

Determines whether the collection contains the tree node, visible or hidden.

public bool Contains(TreeNode node, bool subNodes)

Parameters

node TreeNode

tree node to locate

subNodes bool

whether the child nodes of all levels are searched too

Returns

bool

true if node is found; otherwise, false.

ContainsVisible(TreeNode, bool)

Determines whether the tree node is among the visible nodes of the collection.

public bool ContainsVisible(TreeNode node, bool subNodes)

Parameters

node TreeNode

tree node to locate

subNodes bool

whether the child nodes of all levels of the visible nodes are searched too

Returns

bool

true if node is found; otherwise, false.

CopyTo(Array, int)

Copies the elements of the ICollection to an Array, starting at a particular Array index.

public void CopyTo(Array array, int index)

Parameters

array Array

The one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing.

index int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

index is less than zero.

ArgumentException

array is multidimensional. -or- The number of elements in the source ICollection is greater than the available space from index to the end of the destination array. -or- The type of the source ICollection cannot be cast automatically to the type of the destination array.

GetEnumerator()

Returns an enumerator that iterates through a collection.

public IEnumerator GetEnumerator()

Returns

IEnumerator

An IEnumerator object that can be used to iterate through the collection.

GetVisibility(int)

Gets the visibility of the tree node by index.

public bool GetVisibility(int index)

Parameters

index int

index of treenode among all nodes, hidden ones included

Returns

bool

true if the node at index is visible; otherwise, false.

GetVisibility(string)

Gets the visibility of the tree node by key.

public bool GetVisibility(string key)

Parameters

key string

tree node key

Returns

bool

true if a visible node of the collection has the name key; otherwise, false.

GetVisibility(TreeNode)

Gets the visibility of the tree node by node.

public bool GetVisibility(TreeNode node)

Parameters

node TreeNode

tree node

Returns

bool

true if node is among the visible nodes of the collection; otherwise, false.

Insert(int, string)

Creates a tree node with the specified text and inserts it at the specified index.

public virtual TreeNode Insert(int index, string text)

Parameters

index int

The location within the collection to insert the node.

text string

The text to display in the tree node.

Returns

TreeNode

The TreeNode that was inserted in the collection.

Insert(int, string, string)

Creates a tree node with the specified text and key, and inserts it into the collection.

public virtual TreeNode Insert(int index, string key, string text)

Parameters

index int

The location within the collection to insert the node.

key string

The name of the tree node.

text string

The text to display in the tree node.

Returns

TreeNode

The TreeNode that was inserted in the collection.

Insert(int, string, string, int)

Creates a tree node with the specified key, text, and image, and inserts it into the collection at the specified index.

public virtual TreeNode Insert(int index, string key, string text, int imageIndex)

Parameters

index int

The location within the collection to insert the node.

key string

The name of the tree node.

text string

The text to display in the tree node.

imageIndex int

The index of the image to display in the tree node.

Returns

TreeNode

The TreeNode that was inserted in the collection.

Insert(int, string, string, int, int)

Creates a tree node with the specified key, text, and images, and inserts it into the collection at the specified index.

public virtual TreeNode Insert(int index, string key, string text, int imageIndex, int selectedImageIndex)

Parameters

index int

The location within the collection to insert the node.

key string

The name of the tree node.

text string

The text to display in the tree node.

imageIndex int

The index of the image to display in the tree node.

selectedImageIndex int

The index of the image to display in the tree node when it is in a selected state.

Returns

TreeNode

The TreeNode that was inserted in the collection.

Insert(int, string, string, string)

Creates a tree node with the specified key, text, and image, and inserts it into the collection at the specified index.

public virtual TreeNode Insert(int index, string key, string text, string imageKey)

Parameters

index int

The location within the collection to insert the node.

key string

The name of the tree node.

text string

The text to display in the tree node.

imageKey string

The key of the image to display in the tree node.

Returns

TreeNode

The TreeNode that was inserted in the collection.

Insert(int, string, string, string, string)

Creates a tree node with the specified key, text, and images, and inserts it into the collection at the specified index.

public virtual TreeNode Insert(int index, string key, string text, string imageKey, string selectedImageKey)

Parameters

index int

The location within the collection to insert the node.

key string

The name of the tree node.

text string

The text to display in the tree node.

imageKey string

The key of the image to display in the tree node.

selectedImageKey string

The key of the image to display in the tree node when it is in a selected state.

Returns

TreeNode

The TreeNode that was inserted in the collection.

Insert(int, TreeNode)

Inserts an existing tree node into the tree node collection at the specified location.

public virtual void Insert(int index, TreeNode node)

Parameters

index int

The indexed location within the collection to insert the tree node.

node TreeNode

The TreeNode to insert into the collection.

Exceptions

ArgumentException

The node is currently assigned to another TreeView.

OnTreeNodeAdded(ExTreeViewNodeAddedEventArgs)

Raises the TreeNodeAdded event.

protected virtual void OnTreeNodeAdded(ExTreeViewNodeAddedEventArgs e)

Parameters

e ExTreeViewNodeAddedEventArgs

The event data.

OnTreeNodeRemoved(ExTreeViewNodeRemovedEventArgs)

Raises the TreeNodeRemoved event.

protected virtual void OnTreeNodeRemoved(ExTreeViewNodeRemovedEventArgs e)

Parameters

e ExTreeViewNodeRemovedEventArgs

The event data.

Remove(TreeNode)

Removes the tree node from the collection, even if it is hidden, and from its parent in the tree.

public virtual void Remove(TreeNode node)

Parameters

node TreeNode

The TreeNode to remove.

RemoveAt(int)

Removes a tree node from the tree node collection at a specified index.

public virtual void RemoveAt(int index)

Parameters

index int

The index of the TreeNode to remove.

RemoveByKey(string)

Removes the tree node with the specified key from the collection.

public virtual void RemoveByKey(string key)

Parameters

key string

The name of the tree node to remove from the collection.

SetVisibility(int, bool)

Sets the visibility of the tree node by index.

public void SetVisibility(int index, bool visible)

Parameters

index int

index of the tree node among all nodes, hidden ones included

visible bool

whether node should be visible

Exceptions

ArgumentOutOfRangeException

index is less than zero or not less than the number of all nodes, hidden ones included.

SetVisibility(string?, bool)

Sets the visibility of the tree node by key.

public void SetVisibility(string? key, bool visible)

Parameters

key string

name of the tree node

visible bool

whether node should be visible

Exceptions

ArgumentOutOfRangeException

No node in the collection or in its subtrees has the name key.

SetVisibility(TreeNode?, bool)

Sets the visibility of the tree node.

public void SetVisibility(TreeNode? node, bool visible)

Parameters

node TreeNode

tree node to show or hide

visible bool

whether node should be visible

SetVisibilityForAll(bool)

Sets the visibility of all tree nodes.

public void SetVisibilityForAll(bool visible)

Parameters

visible bool

whether node should be visible

Events

TreeNodeAdded

Occurs when the new TreeNode was added to TreeNodeCollection.

public event EventHandler<ExTreeViewNodeAddedEventArgs>? TreeNodeAdded

Event Type

EventHandler<ExTreeViewNodeAddedEventArgs>

TreeNodeRemoved

Occurs when a TreeNode was removed from the collection.

public event EventHandler<ExTreeViewNodeRemovedEventArgs>? TreeNodeRemoved

Event Type

EventHandler<ExTreeViewNodeRemovedEventArgs>