This documentation is archived and is not being maintained.

TreeNode.ExpandAll Method

Expands all the child tree nodes.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public void ExpandAll()

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


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.

The following code 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 requires that 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).

private void myCheckBox_CheckedChanged(object sender, System.EventArgs e)
   // If the check box is checked, expand all the tree nodes.
   if (myCheckBox.Checked == true)
      // If the check box is not cheked, collapse the first tree node.
      MessageBox.Show("The first and last  node of CutomerList root node is collapsed");

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.