TreeView.ExpandAll メソッド

定義

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

public:
 void ExpandAll();
public void ExpandAll ();
member this.ExpandAll : unit -> unit
Public Sub ExpandAll ()

次のコード例では、 がオンのときにコントロールCheckBox内のすべてのツリー ノードをTreeView展開し、 がクリアされたときに CheckBoxFirstNode折りたたみます。 この例では、 を持FormCheckBoxと、TreeView複数TreeNodeのオブジェクト (できれば 3 つ以上のレベルを持つTreeNodeCollection) を持つ コントロールが必要です。

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 checked, collapse the first tree node.
      myTreeView->Nodes[ 0 ]->FirstNode->Collapse();
      MessageBox::Show( "The first node of CustomerList 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.Checked == true)
   {
      myTreeView.ExpandAll();
   }
   else
   {
      // If the check box is not checked, collapse the first tree node.
      myTreeView.Nodes[0].FirstNode.Collapse();
      MessageBox.Show("The first node of CustomerList root node is collapsed");
   }
}
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 checked, collapse the first tree node.
      myTreeView.Nodes(0).FirstNode.Collapse()
      MessageBox.Show("The first node of CustomerList root node is collapsed")
   End If
End Sub

注釈

メソッドは ExpandAll 、コントロール内 TreeNode にあるすべての子ツリー ノードを含むすべてのオブジェクトを TreeView 展開します。

Note

の状態が TreeNode 保持されます。 たとえば、 メソッドを呼び出 ExpandAll した後、個々のルート ツリー ノードが折りたたまれているとします。 子ツリー ノードは折りたたまれていません。ルート ツリー ノードが再び展開されると、以前に展開された状態で表示されます。 メソッドを CollapseAll 呼び出すと、すべてのツリー ノードが折りたたまれた状態で表示されます。

適用対象

こちらもご覧ください