TreeNode.ExpandAll 方法

定義

展開所有子樹狀節點。

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

範例

下列程式碼範例會在檢查 時 CheckBox 展開 控制項中的所有 TreeView 樹狀節點,並在 清除 時 CheckBox 折迭 FirstNode 。 此範例需要您具有 Form 具有 的 ,以及 TreeView 具有數 TreeNodeCheckBox 物件的 控制項 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 會展開指派給 Nodes 集合的所有子樹狀節點。

注意

的狀態 TreeNode 會保存。 例如,如果先前未折迭下一層子節點,則呼叫 方法時 Expand ,子節點會顯示在其先前展開的狀態。

適用於

另請參閱