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
nodesTreeNodeCollectionThe 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
IsReadOnly
Gets a value indicating whether the IList is read-only.
public virtual bool IsReadOnly { get; }
Property Value
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
indexintThe zero-based index of the element to get or set.
Property Value
- TreeNode
The element at the specified index.
Exceptions
- ArgumentOutOfRangeException
indexis 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
keystringThe name of the tree node to retrieve.
Property Value
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
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
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
Returns
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
Returns
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
keystringThe name of the tree node.
textstringThe text to display in the tree node.
imageIndexintThe index of the image to display in the tree node.
Returns
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
keystringThe name of the tree node.
textstringThe text to display in the tree node.
imageIndexintThe index of the image to display in the tree node.
selectedImageIndexintThe 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
keystringThe name of the tree node.
textstringThe text to display in the tree node.
imageKeystringThe image to display in the tree node.
Returns
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
keystringThe name of the tree node.
textstringThe text to display in the tree node.
imageKeystringThe key of the image to display in the tree node.
selectedImageKeystringThe key of the image to display when the node is in a selected state.
Returns
Add(TreeNode)
Adds a previously created tree node to the end of the tree node collection.
public virtual int Add(TreeNode node)
Parameters
Returns
Exceptions
- ArgumentException
The
nodeis 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
Exceptions
- ArgumentNullException
nodesis null.- ArgumentException
nodesis 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
Contains(TreeNode, bool)
Determines whether the collection contains the tree node, visible or hidden.
public bool Contains(TreeNode node, bool subNodes)
Parameters
nodeTreeNodetree node to locate
subNodesboolwhether the child nodes of all levels are searched too
Returns
ContainsVisible(TreeNode, bool)
Determines whether the tree node is among the visible nodes of the collection.
public bool ContainsVisible(TreeNode node, bool subNodes)
Parameters
nodeTreeNodetree node to locate
subNodesboolwhether the child nodes of all levels of the visible nodes are searched too
Returns
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
arrayArrayThe one-dimensional Array that is the destination of the elements copied from ICollection. The Array must have zero-based indexing.
indexintThe zero-based index in
arrayat which copying begins.
Exceptions
- ArgumentNullException
arrayis null.- ArgumentOutOfRangeException
indexis less than zero.- ArgumentException
arrayis multidimensional. -or- The number of elements in the source ICollection is greater than the available space fromindexto the end of the destinationarray. -or- The type of the source ICollection cannot be cast automatically to the type of the destinationarray.
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
indexintindex of treenode among all nodes, hidden ones included
Returns
GetVisibility(string)
Gets the visibility of the tree node by key.
public bool GetVisibility(string key)
Parameters
keystringtree node key
Returns
GetVisibility(TreeNode)
Gets the visibility of the tree node by node.
public bool GetVisibility(TreeNode node)
Parameters
nodeTreeNodetree node
Returns
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
indexintThe location within the collection to insert the node.
textstringThe text to display in the tree node.
Returns
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
indexintThe location within the collection to insert the node.
keystringThe name of the tree node.
textstringThe text to display in the tree node.
Returns
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
indexintThe location within the collection to insert the node.
keystringThe name of the tree node.
textstringThe text to display in the tree node.
imageIndexintThe index of the image to display in the tree node.
Returns
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
indexintThe location within the collection to insert the node.
keystringThe name of the tree node.
textstringThe text to display in the tree node.
imageIndexintThe index of the image to display in the tree node.
selectedImageIndexintThe index of the image to display in the tree node when it is in a selected state.
Returns
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
indexintThe location within the collection to insert the node.
keystringThe name of the tree node.
textstringThe text to display in the tree node.
imageKeystringThe key of the image to display in the tree node.
Returns
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
indexintThe location within the collection to insert the node.
keystringThe name of the tree node.
textstringThe text to display in the tree node.
imageKeystringThe key of the image to display in the tree node.
selectedImageKeystringThe key of the image to display in the tree node when it is in a selected state.
Returns
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
indexintThe indexed location within the collection to insert the tree node.
nodeTreeNodeThe TreeNode to insert into the collection.
Exceptions
- ArgumentException
The
nodeis currently assigned to another TreeView.
OnTreeNodeAdded(ExTreeViewNodeAddedEventArgs)
Raises the TreeNodeAdded event.
protected virtual void OnTreeNodeAdded(ExTreeViewNodeAddedEventArgs e)
Parameters
eExTreeViewNodeAddedEventArgsThe event data.
OnTreeNodeRemoved(ExTreeViewNodeRemovedEventArgs)
Raises the TreeNodeRemoved event.
protected virtual void OnTreeNodeRemoved(ExTreeViewNodeRemovedEventArgs e)
Parameters
eExTreeViewNodeRemovedEventArgsThe 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
RemoveAt(int)
Removes a tree node from the tree node collection at a specified index.
public virtual void RemoveAt(int index)
Parameters
RemoveByKey(string)
Removes the tree node with the specified key from the collection.
public virtual void RemoveByKey(string key)
Parameters
keystringThe 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
indexintindex of the tree node among all nodes, hidden ones included
visibleboolwhether node should be visible
Exceptions
- ArgumentOutOfRangeException
indexis 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
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
SetVisibilityForAll(bool)
Sets the visibility of all tree nodes.
public void SetVisibilityForAll(bool visible)
Parameters
visibleboolwhether node should be visible
Events
TreeNodeAdded
Occurs when the new TreeNode was added to TreeNodeCollection.
public event EventHandler<ExTreeViewNodeAddedEventArgs>? TreeNodeAdded
Event Type
TreeNodeRemoved
Occurs when a TreeNode was removed from the collection.
public event EventHandler<ExTreeViewNodeRemovedEventArgs>? TreeNodeRemoved