語言

TreeNode.ExpandAll 方法

定義

展開所有子樹節點。

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

範例

以下程式碼範例在TreeView檢查 a CheckBox 時展開控制中所有樹節點,清除 時 FirstNode 收CheckBox斂。 這個例子需要你有一個 Form ,且CheckBox有一個控制TreeView點,且該控制TreeNodeCollection點包含多個TreeNode物件(最好有三個或以上層級)。

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

備註

此 ExpandAll 方法會展開所有指派到集合 Nodes 的子樹節點。

Note

a TreeNode 的狀態會持續存在。 例如,若下一層子節點之前未被壓縮,當 Expand 呼叫該方法時,子節點會以先前展開的狀態出現。

適用於

另請參閱