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

TreeNode.ExpandAll メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

現在のノードとそのすべての子ノード展開します

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

Dim instance As TreeNode

instance.ExpandAll
public void ExpandAll ()
public:
void ExpandAll ()
public void ExpandAll ()
解説解説
使用例使用例

ExpandAll メソッド使用してプログラムによって TreeView コントロールノードとそのすべての子ノード展開する方法次のコード例示します。この例を正常に動作させるには、以下のサンプル XML データを、Book.xml という名前のファイルコピーする必要があります

<%@ Page Language="VB" %>

<script runat="server">

  Sub Data_Bound(ByVal sender As
 Object, ByVal e As TreeNodeEventArgs)

    ' Determine the depth of a node as it is bound to data.
    ' If the depth is 1, expand the node.
    If e.Node.Depth = 1 Then

      ' Expand the node using the ExpandAll method.
      e.Node.ExpandAll()

    Else

      ' Collapse the node using the CollapseAll method.
      e.Node.CollapseAll()

    End If

  End Sub

</script>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeNode ExpandAll and CollapseAll Example</h3>
      
      <h5>Expand the root node. Notice that the child nodes are already expanded.</h5>
    
      <asp:TreeView id="BookTreeView" 
         DataSourceID="BookXmlDataSource"
         OnTreeNodeDataBound="Data_Bound"
         runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book"
 TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter"
 TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section"
 TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"
  
         DataFile="Book.xml"
         runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

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

<script runat="server">

  void Data_Bound(Object sender, TreeNodeEventArgs e)
  {

    // Determine the depth of a node as it is bound to data.
    // If the depth is 1, expand the node.
    if(e.Node.Depth == 1)
    {

      // Expand the node using the ExpandAll method.
      e.Node.ExpandAll();

    }
    else
    {

      // Collapse the node using the CollapseAll method.
      e.Node.CollapseAll();

    }

  }

</script>

<html>
  <body>
    <form runat="server">
    
      <h3>TreeNode ExpandAll and CollapseAll Example</h3>
      
      <h5>Expand the root node. Notice that the child nodes are already expanded.</h5>
    
      <asp:TreeView id="BookTreeView" 
         DataSourceID="BookXmlDataSource"
         OnTreeNodeDataBound="Data_Bound"
         runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
         DataFile="Book.xml"
         runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

前の例のサンプル XML データ次のコード示します

<Book Title="Book Title">
    <Chapter Heading="Chapter 1">
        <Section Heading="Section 1">
        </Section>
        <Section Heading="Section 2">
        </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
        <Section Heading="Section 1">
        </Section>
    </Chapter>
</Book>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNode クラス
TreeNode メンバ
System.Web.UI.WebControls 名前空間
TreeView
Expanded
Collapse
CollapseAll
Expand
ExpandAll

TreeNode.ExpandAll メソッド

すべてのツリー ノード展開します

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

Dim instance As TreeNode

instance.ExpandAll
public void ExpandAll ()
public:
void ExpandAll ()
public void ExpandAll ()
解説解説
使用例使用例

CheckBoxオンになったとき TreeView コントロールツリー ノードをすべて展開しCheckBoxオフになったときに FirstNode を折りたたむコード例次に示します。この例は、Form 上に、CheckBoxTreeView コントロール配置され、その TreeView に、複数TreeNode オブジェクト (3 レベル以上を推奨) を持つ TreeNodeCollection が設定されていることを前提にしています。

Private Sub myCheckBox_CheckedChanged(ByVal
 sender As Object, _
   ByVal e As System.EventArgs) Handles
 myCheckBox.CheckedChanged
   ' If the check box is checked, expand all the tree nodes.
   If myCheckBox.Checked = True Then
      myTreeView.ExpandAll()
   Else
      ' If the check box is not cheked, collapse the first tree node.
      myTreeView.Nodes(0).FirstNode.Collapse()
      MessageBox.Show("The first and last node of CutomerList
 root node is collapsed")
   End If
End Sub
private void myCheckBox_CheckedChanged(object
 sender, System.EventArgs e)
{
   // If the check box is checked, expand all the tree nodes.
   if (myCheckBox.Checked == true)
   {
      myTreeView.ExpandAll();
   }
   else
   {
      // If the check box is not cheked, collapse the first tree node.
      myTreeView.Nodes[0].FirstNode.Collapse();
      MessageBox.Show("The first and last  node of CutomerList root node is
 collapsed");
   }
}
void myCheckBox_CheckedChanged( Object^ /*sender*/, System::EventArgs^
 /*e*/ )
{
   
   // If the check box is checked, expand all the tree nodes.
   if ( myCheckBox->Checked == true )
   {
      myTreeView->ExpandAll();
   }
   else
   {
      
      // If the check box is not cheked, collapse the first tree node.
      myTreeView->Nodes[ 0 ]->FirstNode->Collapse();
      MessageBox::Show( "The first and last  node of CutomerList root node is
 collapsed" );
   }
}
private void myCheckBox_CheckedChanged(Object
 sender, System.EventArgs e)
{
    // If the check box is checked, expand all the tree nodes.
    if (myCheckBox.get_Checked() == true) {
 
        myTreeView.ExpandAll();
    }
    else {
        // If the check box is not cheked, collapse the first tree node.
        myTreeView.get_Nodes().get_Item(0).get_FirstNode().Collapse();
        MessageBox.Show("The first and last  node of CutomerList root "
            + "node is collapsed");
    }
} //myCheckBox_CheckedChanged
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

「TreeNode.ExpandAll」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS