Freigeben über


TreeView.AfterCollapse-Ereignis

Tritt ein, wenn der Strukturknoten reduziert wurde.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Event AfterCollapse As TreeViewEventHandler
'Usage
Dim instance As TreeView
Dim handler As TreeViewEventHandler

AddHandler instance.AfterCollapse, handler
public event TreeViewEventHandler AfterCollapse
public:
event TreeViewEventHandler^ AfterCollapse {
    void add (TreeViewEventHandler^ value);
    void remove (TreeViewEventHandler^ value);
}
/** @event */
public void add_AfterCollapse (TreeViewEventHandler value)

/** @event */
public void remove_AfterCollapse (TreeViewEventHandler value)
JScript unterstützt die Verwendung von Ereignissen, aber nicht die Deklaration von neuen Ereignissen.

Hinweise

Weitere Informationen über die Behandlung von Ereignissen finden Sie unter Behandeln von Ereignissen.

Beispiel

Im folgenden Codebeispiel werden alle untergeordneten Strukturknoten eines TreeNode aktualisiert, wenn der Benutzer dessen Aktivierungszustand ändert. Für den folgenden Code ist es erforderlich, dass ein Form mit einer TreeView vorhanden ist, in deren TreeNodeCollection sich TreeNode-Objekte befinden. Die TreeNodeCollection muss über Strukturknoten mit untergeordneten Knoten verfügen.

' Updates all child tree nodes recursively.
Private Sub CheckAllChildNodes(treeNode As TreeNode, nodeChecked As Boolean)
   Dim node As TreeNode
   For Each node In  treeNode.Nodes 
      node.Checked = nodeChecked
      If node.Nodes.Count > 0 Then
         ' If the current node has child nodes, call the CheckAllChildsNodes method recursively.
         Me.CheckAllChildNodes(node, nodeChecked)
      End If
   Next node
End Sub
      
' NOTE   This code can be added to the BeforeCheck event handler instead of the AfterCheck event.
' After a tree node's Checked property is changed, all its child nodes are updated to the same value.
Private Sub node_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles treeView1.AfterCheck
   ' The code only executes if the user caused the checked state to change.
   If e.Action <> TreeViewAction.Unknown Then 
      If e.Node.Nodes.Count > 0 Then
         ' Calls the CheckAllChildNodes method, passing in the current 
         ' Checked value of the TreeNode whose checked state changed. 
         Me.CheckAllChildNodes(e.Node, e.Node.Checked)
      End If
   End If
End Sub 
// Updates all child tree nodes recursively.
private void CheckAllChildNodes(TreeNode treeNode, bool nodeChecked)
{
   foreach(TreeNode node in treeNode.Nodes)
   {
      node.Checked = nodeChecked;
      if(node.Nodes.Count > 0)
      {
         // If the current node has child nodes, call the CheckAllChildsNodes method recursively.
         this.CheckAllChildNodes(node, nodeChecked);
      }
   }
}

// NOTE   This code can be added to the BeforeCheck event handler instead of the AfterCheck event.
// After a tree node's Checked property is changed, all its child nodes are updated to the same value.
private void node_AfterCheck(object sender, TreeViewEventArgs e)
{
   // The code only executes if the user caused the checked state to change.
   if(e.Action != TreeViewAction.Unknown)
   {
      if(e.Node.Nodes.Count > 0)
      {
         /* Calls the CheckAllChildNodes method, passing in the current 
         Checked value of the TreeNode whose checked state changed. */
         this.CheckAllChildNodes(e.Node, e.Node.Checked);
      }
   }
}
// Updates all child tree nodes recursively.
void CheckAllChildNodes( TreeNode^ treeNode, bool nodeChecked )
{
   IEnumerator^ myEnum = treeNode->Nodes->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      TreeNode^ node = safe_cast<TreeNode^>(myEnum->Current);
      node->Checked = nodeChecked;
      if ( node->Nodes->Count > 0 )
      {
         
         // If the current node has child nodes, call the CheckAllChildsNodes method recursively.
         this->CheckAllChildNodes( node, nodeChecked );
      }
   }
}

// NOTE   This code can be added to the BeforeCheck event handler instead of the AfterCheck event.
// After a tree node's Checked property is changed, all its child nodes are updated to the same value.
void node_AfterCheck( Object^ /*sender*/, TreeViewEventArgs^ e )
{
   // The code only executes if the user caused the checked state to change.
   if ( e->Action != TreeViewAction::Unknown )
   {
      if ( e->Node->Nodes->Count > 0 )
      {
         /* Calls the CheckAllChildNodes method, passing in the current
             Checked value of the TreeNode whose checked state changed. */
         this->CheckAllChildNodes( e->Node, e->Node->Checked );
      }
   }
}
// Updates all child tree nodes recursively.
private void CheckAllChildNodes(TreeNode treeNode, boolean nodeChecked)
{
    for (int iCtr = 0; iCtr < treeNode.get_Nodes().get_Count(); iCtr++) {
        TreeNode node = treeNode.get_Nodes().get_Item(iCtr);
        node.set_Checked(nodeChecked);
        if (node.get_Nodes().get_Count() > 0) {
            // If the current node has child nodes, call the
            // CheckAllChildsNodes method recursively.
            this.CheckAllChildNodes(node, nodeChecked);
        }
    }
} //CheckAllChildNodes

// NOTE This code can be added to the BeforeCheck event handler instead 
// of the AfterCheck event. After a tree node's Checked property is 
// changed, all its child nodes are updated to the same value.
private void Node_AfterCheck(Object sender, TreeViewEventArgs e)
{
    // The code only executes if the user caused the checked state to change.
    if (!(e.get_Action().Equals(TreeViewAction.Unknown))) {
        if (e.get_Node().get_Nodes().get_Count() > 0) {
            /* Calls the CheckAllChildNodes method, passing in the current 
               Checked value of the TreeNode whose checked state changed. */
            this.CheckAllChildNodes(e.get_Node(), e.get_Node().get_Checked());
        }
    }
} //Node_AfterCheck

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

TreeView-Klasse
TreeView-Member
System.Windows.Forms-Namespace
OnAfterCollapse
BeforeCollapse
OnBeforeCollapse