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


現在のノードとそのすべての子ノードを簡単に折りたたむには、CollapseAll メソッドを使用します。
![]() |
---|

CollapseAll メソッドを使用して、プログラムによって 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>

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


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

- TreeNode.CollapseAll メソッドのページへのリンク