This documentation is archived and is not being maintained.

TreeNode.ExpandAll Method

Expands all the child tree nodes.

[Visual Basic]
Public Sub ExpandAll()
[C#]
public void ExpandAll();
[C++]
public: void ExpandAll();
[JScript]
public function ExpandAll();

Remarks

The ExpandAll method expands all the child tree nodes assigned to the Nodes collection.

Note   The state of a TreeNode is persisted. For example, if the next level of child nodes was not collapsed previously, when the Expand method is called, the child nodes appear in their previously expanded state.

Example

[Visual Basic, C#, C++] The following example expands all the tree nodes in a TreeView control when a CheckBox is checked, and collapses the FirstNode when the CheckBox is cleared. This example assumes you have a Form with a CheckBox, and a TreeView control with a TreeNodeCollection that has several TreeNode objects (preferably with three or more levels).

[Visual Basic] 
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

[C#] 
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");
   }
}

[C++] 
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->Item[0]->FirstNode->Collapse();
            MessageBox::Show(S"The first and last  node of CutomerList root node is collapsed");
        }
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

TreeNode Class | TreeNode Members | System.Windows.Forms Namespace | Expand | Collapse | IsExpanded | Toggle

Show: