TreeView.AfterCollapse 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
트리 노드가 축소된 후에 발생합니다.
public:
event System::Windows::Forms::TreeViewEventHandler ^ AfterCollapse;
public event System.Windows.Forms.TreeViewEventHandler AfterCollapse;
member this.AfterCollapse : System.Windows.Forms.TreeViewEventHandler
Public Custom Event AfterCollapse As TreeViewEventHandler
이벤트 유형
예제
다음 코드 예제에서는 사용자가 선택한 상태를 변경할 때의 TreeNode 모든 자식 트리 노드를 업데이트합니다. 이 코드를 사용하려면 해당 코드에 개체가 있는 with가 있어야 Form TreeView 합니다TreeNodeCollection.TreeNode 자 TreeNodeCollection 식 노드가 있는 트리 노드가 있어야 합니다.
// 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, 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.
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
설명
이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.