다음을 통해 공유


TreeNode.Parent 속성

현재 트리 노드의 부모 트리 노드를 가져옵니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public ReadOnly Property Parent As TreeNode
‘사용 방법
Dim instance As TreeNode
Dim value As TreeNode

value = instance.Parent
public TreeNode Parent { get; }
public:
property TreeNode^ Parent {
    TreeNode^ get ();
}
/** @property */
public TreeNode get_Parent ()
public function get Parent () : TreeNode

속성 값

현재 트리 노드의 부모를 나타내는 TreeNode입니다.

설명

트리 노드가 루트 수준이면 Parent 속성은 Null 참조(Visual Basic의 경우 Nothing)을 반환합니다.

예제

다음 코드 예제에서는 TreeView.SelectedNodeParent 속성으로 표시되는 TreeNodeTextIndex 속성 값을 표시합니다. 이 예제를 실행하려면 FormTreeView 컨트롤이 있어야 합니다. TreeView는 각각 자식 노드를 하나 이상 가지는 둘 이상의 루트 노드를 갖습니다.

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 (Not e.Node.Parent Is 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 
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:
   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.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.
            ToString(e.get_Node().get_Parent().get_Index()));
    }
    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

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

TreeNode 클래스
TreeNode 멤버
System.Windows.Forms 네임스페이스