TreeView.AfterCheck 이벤트
트리 노드 확인란이 선택된 후에 발생합니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
Public Event AfterCheck As TreeViewEventHandler
‘사용 방법
Dim instance As TreeView
Dim handler As TreeViewEventHandler
AddHandler instance.AfterCheck, handler
public event TreeViewEventHandler AfterCheck
public:
event TreeViewEventHandler^ AfterCheck {
void add (TreeViewEventHandler^ value);
void remove (TreeViewEventHandler^ value);
}
/** @event */
public void add_AfterCheck (TreeViewEventHandler value)
/** @event */
public void remove_AfterCheck (TreeViewEventHandler value)
JScript에서는 이벤트를 사용할 수 있지만 새로 선언할 수는 없습니다.
설명
BeforeCheck 또는 AfterCheck 이벤트 처리기 내에서 TreeNode.Checked 속성을 설정하면 이벤트가 여러 번 발생하여 예상하지 못한 동작이 생길 수 있습니다. TreeViewEventArgs의 Action 속성이 TreeViewAction.Unknown으로 설정되어 있지 않은 경우, 이벤트가 여러 번 발생하지 않도록 하려면 재귀적 코드만 실행하는 이벤트 처리기에 논리를 추가합니다.
이벤트 처리에 대한 자세한 내용은 이벤트 사용을 참조하십시오.
예제
다음 코드 예제에서는 사용자가 TreeNode의 선택 상태를 변경할 때 이 노드의 모든 자식 트리 노드를 업데이트합니다. 이 코드에서는 Form에 TreeView가 있고, 포함된 TreeNodeCollection에 TreeNode 개체가 있어야 합니다. TreeNodeCollection에는 자식 노드가 포함된 트리 노드가 있어야 합니다.
' 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
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
TreeView 클래스
TreeView 멤버
System.Windows.Forms 네임스페이스
TreeView.CheckBoxes 속성
OnAfterCheck
BeforeCheck
OnBeforeCheck