TreeNode.ExpandAll 方法

展开所有子树节点。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Sub ExpandAll
用法
Dim instance As TreeNode

instance.ExpandAll
public void ExpandAll ()
public:
void ExpandAll ()
public void ExpandAll ()
public function ExpandAll ()

备注

ExpandAll 方法展开分配给 Nodes 集合的所有子树节点。

提示

保持 TreeNode 的状态。例如,如果下一级子节点原来未折叠,则在调用 Expand 方法时,子节点将显示为原来展开的状态。

示例

下面的代码示例在选中 CheckBox 时展开 TreeView 控件中的所有树节点,并在清除 CheckBox 时折叠 FirstNode。本示例要求有一个包含 CheckBoxForm 和一个包含 TreeNodeCollectionTreeView 控件,该集合包含若干个 TreeNode 对象(最好具有三级或三级以上)。

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 cheked, collapse the first tree node.
      myTreeView.Nodes(0).FirstNode.Collapse()
      MessageBox.Show("The first and last node of CutomerList root node is collapsed")
   End If
End Sub
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 cheked, collapse the first tree node.
      myTreeView.Nodes[0].FirstNode.Collapse();
      MessageBox.Show("The first and last  node of CutomerList root node is collapsed");
   }
}
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 cheked, collapse the first tree node.
      myTreeView->Nodes[ 0 ]->FirstNode->Collapse();
      MessageBox::Show( "The first and last  node of CutomerList 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.get_Checked() == true) { 
        myTreeView.ExpandAll();
    }
    else {
        // If the check box is not cheked, collapse the first tree node.
        myTreeView.get_Nodes().get_Item(0).get_FirstNode().Collapse();
        MessageBox.Show("The first and last  node of CutomerList root "
            + "node is collapsed");
    }
} //myCheckBox_CheckedChanged

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

TreeNode 类
TreeNode 成员
System.Windows.Forms 命名空间
Expand
Collapse
IsExpanded
Toggle