TreeNode.Parentとは? わかりやすく解説

TreeNode.Parent プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

現在のノード親ノード取得します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

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 ()

プロパティ
現在のノード親ノードを表す TreeNode。

解説解説
使用例使用例

Parent プロパティ使用して現在のノード親ノードText プロパティアクセスする方法次のコード例示します

<%@ Page Language="VB" %>

<script runat="server">

  Sub Selection_Changed(ByVal sender As
 Object, ByVal e As EventArgs)

    ' Display the selected node and its parent node.
    Message.Text = "You selected " & LinksTreeView.SelectedNode.Text
 & ". "

    If LinksTreeView.SelectedNode.Parent.Depth <> -1 Then

      Message.Text &= "Its parent node is " &
 LinksTreeView.SelectedNode.Parent.Text & "."

    Else

      Message.Text &= "This is a root node and does not have
 a parent node."

    End If

  End Sub

</script>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeNode Parent Example</h3>
      
      <h5>Select a node from the TreeView control.</h5>
    
      <asp:TreeView id="LinksTreeView"
        Font-Name= "Arial"
        ForeColor="Blue"
        InitialExpandDepth="2"
        OnSelectedNodeChanged="Selection_Changed"
 
        runat="server">
         
        <LevelStyles>
        
          <asp:TreeNodeStyle ChildNodesPadding="10"
 
            Font-Bold="true" 
            Font-Size="12pt" 
            ForeColor="DarkGreen"/>
          <asp:TreeNodeStyle ChildNodesPadding="5"
 
            Font-Bold="true" 
            Font-Size="10pt"/>
          <asp:TreeNodeStyle ChildNodesPadding="5"
 
            Font-UnderLine="true" 
            Font-Size="10pt"/>
          <asp:TreeNodeStyle ChildNodesPadding="10"
 
            Font-Size="8pt"/>
             
        </LevelStyles>
         
        <Nodes>
        
          <asp:TreeNode Text="Table of Contents">
             
            <asp:TreeNode Text="Chapter One">
            
              <asp:TreeNode Text="Section 1.0">
              
                <asp:TreeNode Text="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3"/>
              
              </asp:TreeNode>
              
              <asp:TreeNode Text="Section 1.1">
              
                <asp:TreeNode Text="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
            <asp:TreeNode Text="Chapter Two">
            
              <asp:TreeNode Text="Section 2.0">
              
                <asp:TreeNode Text="Topic 2.0.1"/>
                <asp:TreeNode Text="Topic 2.0.2"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
          </asp:TreeNode>
          
          <asp:TreeNode Text="Appendix A" />
          <asp:TreeNode Text="Appendix B" />
          <asp:TreeNode Text="Appendix C" />
        
        </Nodes>
        
      </asp:TreeView>
      
      <br><br>
      
      <asp:Label id="Message"
         runat="server"/>   

    </form>
  </body>
</html>

<%@ Page Language="C#" %>

<script runat="server">

  void Selection_Changed(Object sender, EventArgs e)
  {

    // Display the selected node and its parent node.
    Message.Text = "You selected " + LinksTreeView.SelectedNode.Text +
 ". ";

    if(LinksTreeView.SelectedNode.Parent.Depth != -1)
    {

      Message.Text += "Its parent node is " + LinksTreeView.SelectedNode.Parent.Text
 + ".";

    }
    else
    {

      Message.Text += "This is a root node and does not have a parent node.";

    }

  }

</script>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeNode Parent Example</h3>
      
      <h5>Select a node from the TreeView control.</h5>
    
      <asp:TreeView id="LinksTreeView"
        Font-Name= "Arial"
        ForeColor="Blue"
        InitialExpandDepth="2"
        OnSelectedNodeChanged="Selection_Changed" 
        runat="server">
         
        <LevelStyles>
        
          <asp:TreeNodeStyle ChildNodesPadding="10" 
            Font-Bold="true" 
            Font-Size="12pt" 
            ForeColor="DarkGreen"/>
          <asp:TreeNodeStyle ChildNodesPadding="5" 
            Font-Bold="true" 
            Font-Size="10pt"/>
          <asp:TreeNodeStyle ChildNodesPadding="5" 
            Font-UnderLine="true" 
            Font-Size="10pt"/>
          <asp:TreeNodeStyle ChildNodesPadding="10" 
            Font-Size="8pt"/>
             
        </LevelStyles>
         
        <Nodes>
        
          <asp:TreeNode Text="Table of Contents">
             
            <asp:TreeNode Text="Chapter One">
            
              <asp:TreeNode Text="Section 1.0">
              
                <asp:TreeNode Text="Topic 1.0.1"/>
                <asp:TreeNode Text="Topic 1.0.2"/>
                <asp:TreeNode Text="Topic 1.0.3"/>
              
              </asp:TreeNode>
              
              <asp:TreeNode Text="Section 1.1">
              
                <asp:TreeNode Text="Topic 1.1.1"/>
                <asp:TreeNode Text="Topic 1.1.2"/>
                <asp:TreeNode Text="Topic 1.1.3"/>
                <asp:TreeNode Text="Topic 1.1.4"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
            <asp:TreeNode Text="Chapter Two">
            
              <asp:TreeNode Text="Section 2.0">
              
                <asp:TreeNode Text="Topic 2.0.1"/>
                <asp:TreeNode Text="Topic 2.0.2"/>
              
              </asp:TreeNode>
            
            </asp:TreeNode>
            
          </asp:TreeNode>
          
          <asp:TreeNode Text="Appendix A" />
          <asp:TreeNode Text="Appendix B" />
          <asp:TreeNode Text="Appendix C" />
        
        </Nodes>
        
      </asp:TreeView>
      
      <br><br>
      
      <asp:Label id="Message"
         runat="server"/>   

    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNode クラス
TreeNode メンバ
System.Web.UI.WebControls 名前空間
TreeView
TreeNode.ChildNodes プロパティ

TreeNode.Parent プロパティ

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

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

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 ()

プロパティ
現在のツリー ノードの親を表す TreeNode。

解説解説
使用例使用例

TreeView.SelectedNode の Parent プロパティが表す TreeNodeIndex プロパティText プロパティの値を表示するコード例次に示します。この例では、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 
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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からTreeNode.Parentを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTreeNode.Parentを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTreeNode.Parent を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TreeNode.Parent」の関連用語

TreeNode.Parentのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeNode.Parentのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS