TreeNode.Parent 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取当前树节点的父树节点。
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; }
member this.Parent : System.Windows.Forms.TreeNode
[<System.ComponentModel.Browsable(false)>]
member this.Parent : System.Windows.Forms.TreeNode
Public ReadOnly Property Parent As TreeNode
属性值
TreeNode,表示当前树节点的父树节点。
- 属性
示例
下面的代码示例显示Text由属性TreeView.SelectedNode表示Parent的和Index属性值TreeNode。 此示例要求你具有FormTreeView控件。 应 TreeView 至少有两个根节点,每个节点至少有一个子节点。
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
注解
如果树节点位于根级别,则 Parent 属性返回 null
。