TreeView.ExpandAll 方法

定义

展开所有树节点。

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

示例

下面的代码示例在选中控件时CheckBox展开控件中的所有树节点TreeView,并折叠FirstNode清除时间CheckBox。 此示例要求你有一个具有一CheckBoxForm控件,一个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 == 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调用该方法可确保所有树节点都处于折叠状态。

适用于

另请参阅