Share via


TreeView.ExpandAll 方法

展开所有树节点。

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

语法

声明
Public Sub ExpandAll
用法
Dim instance As TreeView

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

备注

ExpandAll 方法展开 TreeView 控件中的所有 TreeNode 对象(包括所有子树节点)。

提示

保持 TreeNode 的状态。例如,假定您调用 ExpandAll 方法,然后折叠单个根树节点。此时子树节点尚未折叠,因此当根树节点再次展开时,子树节点将以先前的展开状态出现。调用 CollapseAll 方法可确保所有树节点都显示为折叠状态。

示例

下面的代码示例在选中 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

请参见

参考

TreeView 类
TreeView 成员
System.Windows.Forms 命名空间
Expand
CollapseAll