.NET Framework クラス ライブラリ
TreeNode.Parent プロパティ

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

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

構文

Visual Basic (宣言)
Public ReadOnly Property Parent As TreeNode
Visual Basic (使用法)
Dim instance As TreeNode
Dim value As TreeNode

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

プロパティ値

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

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

使用例

TreeView.SelectedNodeParent プロパティが表す TreeNodeIndex プロパティと Text プロパティの値を表示するコード例を次に示します。この例では、TreeView コントロールが配置された Form が存在している必要があります。TreeView コントロールは 2 つ以上のルート ノードを持ち、各ルート ノードに 1 つ以上の子ノードを持っている必要があります。

Visual Basic
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 != 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.";
      }
   }
J#
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
参照

タグ :


Page view tracker