次の方法で共有


TreeNode.Parent プロパティ

現在のツリー ノードの親ツリー ノードを取得します。

Public ReadOnly Property Parent As TreeNode
[C#]
public TreeNode Parent {get;}
[C++]
public: __property TreeNode* get_Parent();
[JScript]
public function get Parent() : TreeNode;

プロパティ値

現在のツリー ノードの親を表す TreeNode

解説

ツリー ノードがルート レベルにある場合、 Parent プロパティは null 参照 (Visual Basic では Nothing) を返します。

使用例

[Visual Basic, C#, C++] TreeView.SelectedNodeParent プロパティが表す TreeNodeText プロパティと Index プロパティの値を表示する例を次に示します。この例は、 TreeView コントロールが配置された Form があることを前提にしています。 TreeView コントロールは 2 つ以上のルート ノードを持ち、各ルート ノードに 1 つ以上の子ノードを持っている必要があります。

 
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 

[C#] 
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.";
   }
}

[C++] 
private:
   void treeView1_AfterSelect(Object* /*sender*/, TreeViewEventArgs* e) {
      /* Display the Text and Index of the
      * selected tree node's Parent. */
      if (e->Node->Parent!= 0 &&
         e->Node->Parent->GetType() == __typeof(TreeNode)) {
            statusBar1->Text = String::Format( S"Parent: {0}\n Index Position: {1}", e->Node->Parent->Text, __box(e->Node->Parent->Index));
         } else {
            statusBar1->Text = S"No parent node.";
         }
   }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

TreeNode クラス | TreeNode メンバ | System.Windows.Forms 名前空間