TreeNode.ExpandAll Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Expands all the child tree nodes.
public:
void ExpandAll();
public void ExpandAll ();
member this.ExpandAll : unit -> unit
Public Sub ExpandAll ()
Examples
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).
void myCheckBox_CheckedChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// If the check box is checked, expand all the tree nodes.
if ( myCheckBox->Checked )
{
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)
{
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
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.
Applies to
See also
.NET