Export (0) Print
Expand All

TreeNode.Nodes Property

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
<ListBindableAttribute(False)> _
<BrowsableAttribute(False)> _
Public ReadOnly Property Nodes As TreeNodeCollection

Property Value

Type: System.Windows.Forms.TreeNodeCollection
A TreeNodeCollection that represents the tree nodes assigned to the current tree node.

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.

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.

Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
   ' If neither TreeNodeCollection is read-only, move the  
   ' selected node from treeView1 to treeView2.  
   If Not treeView1.Nodes.IsReadOnly And Not treeView2.Nodes.IsReadOnly Then 
      If (treeView1.SelectedNode IsNot Nothing) Then 
         Dim tn As TreeNode = treeView1.SelectedNode
         treeView1.Nodes.Remove(tn)
         treeView2.Nodes.Insert(treeView2.Nodes.Count, tn)
      End If 
   End If 
End Sub

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft