TreeNode.Parent Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the parent tree node of the current tree node.
public:
property System::Windows::Forms::TreeNode ^ Parent { System::Windows::Forms::TreeNode ^ get(); };
public System.Windows.Forms.TreeNode Parent { get; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.TreeNode Parent { get; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.TreeNode? Parent { get; }
member this.Parent : System.Windows.Forms.TreeNode
[<System.ComponentModel.Browsable(false)>]
member this.Parent : System.Windows.Forms.TreeNode
Public ReadOnly Property Parent As TreeNode
Property Value
A TreeNode that represents the parent of the current tree node.
- Attributes
Examples
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 != 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 );
}
else
{
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.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.";
}
}
Private Sub treeView1_AfterSelect(sender As Object, _
e As TreeViewEventArgs) Handles treeView1.AfterSelect
' Display the Text and Index of the
' selected tree node's Parent.
If (e.Node.Parent IsNot Nothing)
If (e.Node.Parent.GetType() Is GetType(TreeNode)) Then
statusBar1.Text = "Parent: " + e.Node.Parent.Text + _
ControlChars.Cr + "Index Position: " + e.Node.Parent.Index.ToString()
End If
Else
statusBar1.Text = "No parent node."
End If
End Sub
Remarks
If the tree node is at the root level, the Parent property returns null
.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기