Export (0) Print
Expand All

TreeNode::Parent Property

Gets the parent tree node of the current tree node.

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

property TreeNode^ Parent {
	TreeNode^ get ();

Property Value

Type: System.Windows.Forms::TreeNode
A TreeNode that represents the parent of the current tree node.

If the tree node is at the root level, the Parent property returns nullptr.

The following code example displays the Text and Index property values of the TreeNode represented by the Parent property of the TreeView::SelectedNode. This example requires that you have a Form with a TreeView control on it. The TreeView should have at least two root nodes, each having at least one child node.

   void treeView1_AfterSelect( Object^ /*sender*/, TreeViewEventArgs^ e )
      /* Display the Text and Index of the
            * selected tree node's Parent. */ 
      if ( e->Node->Parent != nullptr && e->Node->Parent->GetType() == TreeNode::typeid )
         statusBar1->Text = String::Format( "Parent: {0}\n Index Position: {1}", e->Node->Parent->Text, e->Node->Parent->Index );
         statusBar1->Text = "No parent node.";

.NET Framework

Supported in: 4.6, 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.

© 2014 Microsoft