TreeNode.ExpandAll Metod

Definition

Expanderar alla underordnade trädnoder.

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

Exempel

Följande kodexempel expanderar alla trädnoder i en TreeView kontroll när en CheckBox markeras och minimerar FirstNode när CheckBox avmarkerad. Det här exemplet kräver att du har en Form med en CheckBox, och en TreeView kontroll med en TreeNodeCollection som har flera TreeNode objekt (helst med tre eller fler nivåer).

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

Kommentarer

Metoden ExpandAll expanderar alla underordnade trädnoder som tilldelats samlingen Nodes .

Note

Tillståndet för en TreeNode sparas. Om till exempel nästa nivå av underordnade noder inte har komprimerats tidigare visas de underordnade noderna i sitt tidigare expanderade tillstånd när Expand metoden anropas.

Gäller för

Se även