TreeNode.ExpandAll Método

Definição

Expande todos os nós de árvore filho.

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

Exemplos

O exemplo de código a seguir expande todos os nós de árvore em um TreeView controle quando um CheckBox é verificado e recolhe o FirstNode quando ele CheckBox é desmarcado. Este exemplo requer que você tenha um Form controle com um CheckBoxe um TreeView controle com um TreeNodeCollection que tenha vários TreeNode objetos (de preferência com três ou mais níveis).

void myCheckBox_CheckedChanged( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{

   // If the check box is checked, expand all the tree nodes.
   if ( myCheckBox->Checked )
   {
      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)
   {
      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

Comentários

O ExpandAll método expande todos os nós de árvore filho atribuídos à Nodes coleção.

Note

O estado de um TreeNode é persistente. Por exemplo, se o próximo nível de nós filho não tiver sido recolhido anteriormente, quando o Expand método for chamado, os nós filho aparecerão em seu estado expandido anteriormente.

Aplica-se a

Confira também