TreeNode.Nodes Property

Definition

Gets the collection of TreeNode objects assigned to the current tree node.

C#
[System.ComponentModel.ListBindable(false)]
public System.Windows.Forms.TreeNodeCollection Nodes { get; }
C#
[System.ComponentModel.ListBindable(false)]
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.TreeNodeCollection Nodes { get; }

Property Value

A TreeNodeCollection that represents the tree nodes assigned to the current tree node.

Attributes

Examples

The following code example removes the selected tree node from one TreeView and adds it to another if both tree node collections are not read-only. When a Button is clicked, the TreeView.SelectedNode is deleted from one TreeView using the Remove method and added to the other TreeView using the Insert method. This example requires that you have two TreeView controls named treeView1 and treeView2, and a Button on a Form.

C#
private void button1_Click(object sender, EventArgs e)
{
   // If neither TreeNodeCollection is read-only, move the 
   // selected node from treeView1 to treeView2.
   if(!treeView1.Nodes.IsReadOnly && !treeView2.Nodes.IsReadOnly)
   {
      if(treeView1.SelectedNode != null)
      {
         TreeNode tn = treeView1.SelectedNode;
         treeView1.Nodes.Remove(tn);
         treeView2.Nodes.Insert(treeView2.Nodes.Count, tn);
      }
   }
}

Remarks

The Nodes property can hold a collection of other TreeNode objects. Each of the tree node in the collection has a Nodes property that can contain its own TreeNodeCollection. This nesting of tree nodes can make it difficult to navigate a tree structure. The FullPath property makes it easier to determine your location in a tree.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also