TreeView.ExpandAll メソッド
アセンブリ: System.Web (system.web.dll 内)



ExpandAll メソッドを使用して、TreeView コントロール内のすべてのノードを同時に展開する方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Button_Command(ByVal sender As Object, ByVal e As CommandEventArgs) Select Case e.CommandName Case "Expand" LinksTreeView.ExpandAll() Case "Collapse" LinksTreeView.CollapseAll() Case Else ' Do nothing. End Select End Sub </script> <html> <body> <form runat="server"> <h3>TreeView ExpandAll and CollapseAll Example</h3> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" 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" SelectAction="None"> <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> <hr> <asp:Button id="ExpandButton" CommandName="Expand" Text="Expand All Nodes" OnCommand="Button_Command" runat="server"/> <asp:Button id="CollapseButton" CommandName="Collapse" Text="Collapse All Nodes" OnCommand="Button_Command" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Button_Command(Object sender, CommandEventArgs e) { switch(e.CommandName) { case "Expand": LinksTreeView.ExpandAll(); break; case "Collapse": LinksTreeView.CollapseAll(); break; default: // Do nothing. break; } } </script> <html> <body> <form runat="server"> <h3>TreeView ExpandAll and CollapseAll Example</h3> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" 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" SelectAction="None"> <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> <hr> <asp:Button id="ExpandButton" CommandName="Expand" Text="Expand All Nodes" OnCommand="Button_Command" runat="server"/> <asp:Button id="CollapseButton" CommandName="Collapse" Text="Collapse All Nodes" OnCommand="Button_Command" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeView.ExpandAll メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


ExpandAll メソッドは、TreeView コントロール内の、子ツリー ノードを含むすべての TreeNode オブジェクトを展開します。
![]() |
---|
TreeNode の状態は永続的です。たとえば、ExpandAll メソッドを呼び出してから、それぞれのルート ツリー ノードを折りたたむとします。子ツリー ノードは折りたたまれていないため、ルート ツリー ノードを再度展開したときに、これらの子ツリー ノードは以前展開されたときの状態で表示されます。CollapseAll メソッドを呼び出すと、確実にすべてのツリー ノードを折りたたんだ状態で表示できます。 |

Checkbox がオンになったとき TreeView コントロールのツリー ノードをすべて展開し、Checkbox がオフになったときに FirstNode を折りたたむコード例を次に示します。この例は、Form 上に、Checkbox と TreeView コントロール が配置され、その 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

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTreeView.ExpandAllを検索する場合は、下記のリンクをクリックしてください。

- TreeView.ExpandAllのページへのリンク