TreeNode.ExpandAll TreeNode.ExpandAll TreeNode.ExpandAll TreeNode.ExpandAll Method

定義

展開所有子樹狀節點。Expands all the child tree nodes.

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

範例

下列TreeView CheckBox程式碼範例會在FirstNode核取時展開控制項中的所有樹狀節點, CheckBox並在清除時折迭。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. 這個範例需要Form您具有CheckBox具有的, TreeNodeCollection以及TreeView具有具有數個TreeNode物件之的控制項(最好是三個以上的層級)。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 == 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

備註

方法會展開所有指派Nodes給集合的子樹狀節點。 ExpandAllThe ExpandAll method expands all the child tree nodes assigned to the Nodes collection.

注意

的狀態TreeNode會保存。The state of a TreeNode is persisted. 例如,如果先前未折迭子節點的下一個層級,則在Expand呼叫方法時,子節點會出現在先前展開的狀態中。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.

適用於

另請參閱