TreeNode.Parent Property

Gets the parent tree node of the current tree node.

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

public TreeNode Parent { get; }
/** @property */
public TreeNode get_Parent ()

public function get Parent () : TreeNode

Property Value

A TreeNode that represents the parent of the current tree node.

If the tree node is at the root level, the Parent property returns a null reference (Nothing in Visual Basic).

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.

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
   /* Display the Text and Index of the 
    * selected tree node's Parent. */
   if(e.Node.Parent!= null && 
     e.Node.Parent.GetType() == typeof(TreeNode) )
      statusBar1.Text = "Parent: " + e.Node.Parent.Text + "\n"
         + "Index Position: " + e.Node.Parent.Index.ToString();
      statusBar1.Text = "No parent node.";

private void treeView1_AfterSelect(Object sender, TreeViewEventArgs e)
    /* Display the Text and Index of the 
       selected tree node's Parent. 
    if (e.get_Node().get_Parent() != null && e.get_Node().get_Parent().
        GetType().Equals(TreeNode.class.ToType())) {
        statusBar1.set_Text("Parent: " + e.get_Node().get_Parent().
            get_Text() + "\n" + "Index Position: " + System.Convert.
    else {
        statusBar1.set_Text("No parent node.");
} //treeView1_AfterSelect

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0