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)
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(); } else { statusBar1.Text = "No parent node."; } }
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.