TreeView.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 會展開控制項 TreeNode 中的所有 TreeView 物件,其中包含所有子樹狀節點。

注意

保存的狀態 TreeNode 。 例如,假設您呼叫 ExpandAll 方法,然後折迭個別的根樹狀節點。 子樹狀節點尚未折迭,而且會在根樹狀節點再次展開時,顯示為其先前展開的狀態。 CollapseAll呼叫 方法可確保所有樹狀節點都處於折迭狀態。

適用於

另請參閱