TreeView.ExpandAll Метод

Определение

Развертывает все узлы дерева.

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

Примеры

В следующем примере кода развертываются все узлы дерева в элементе TreeView управления при 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 == 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 Вызов метода гарантирует, что все узлы дерева отображаются в свернутом состоянии.

Применяется к

См. также раздел