TreeView.ExpandAll Metodo

Definizione

Espande tutti i nodi della struttura ad albero.

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

Esempio

Nell'esempio di codice seguente vengono espansi tutti i nodi della struttura ad albero in un TreeView controllo quando un CheckBox oggetto viene controllato e viene FirstNode compresso quando CheckBox viene cancellato . Questo esempio richiede che sia presente un Form oggetto con un CheckBoxe un TreeView controllo con un TreeNodeCollection oggetto che dispone di più TreeNode oggetti (preferibilmente con tre o più livelli).

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

Commenti

Il ExpandAll metodo espande tutti gli TreeNode oggetti, che includono tutti i nodi della struttura ad albero figlio, inclusi nel TreeView controllo .

Note

Lo stato di un oggetto TreeNode persiste. Si supponga, ad esempio, di chiamare il ExpandAll metodo e quindi di comprimere i singoli nodi dell'albero radice. I nodi dell'albero figlio non sono stati compressi e verranno visualizzati nello stato espanso in precedenza quando i nodi dell'albero radice vengono espansi di nuovo. La chiamata al CollapseAll metodo garantisce che tutti i nodi della struttura ad albero vengano visualizzati nello stato compresso.

Si applica a

Vedi anche