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



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>

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


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


ExpandAll メソッドは、Nodes コレクションに割り当てられているすべての子ツリー ノードを展開します。
![]() |
---|
TreeNode の状態は永続化されています。たとえば、次のレベルの子ノードの表示が折りたたまれていなかった場合、Expand メソッドを呼び出すと、それらの子ノードは前回展開されたときの状態で表示されます。 |

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に収録されているすべての辞書からTreeNode.ExpandAllを検索する場合は、下記のリンクをクリックしてください。

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