TreeViewCancelEventArgs TreeViewCancelEventArgs TreeViewCancelEventArgs TreeViewCancelEventArgs Class

정의

BeforeCheck 컨트롤의 BeforeCollapse, BeforeExpand, BeforeSelectTreeView 이벤트에 대한 날짜를 지정합니다.Provides data for the BeforeCheck, BeforeCollapse, BeforeExpand, and BeforeSelect events of a TreeView control.

public ref class TreeViewCancelEventArgs : System::ComponentModel::CancelEventArgs
public class TreeViewCancelEventArgs : System.ComponentModel.CancelEventArgs
type TreeViewCancelEventArgs = class
    inherit CancelEventArgs
Public Class TreeViewCancelEventArgs
Inherits CancelEventArgs
상속
TreeViewCancelEventArgsTreeViewCancelEventArgsTreeViewCancelEventArgsTreeViewCancelEventArgs

예제

다음 예제에서는 축소 상태를 변경 하는 방법에 설명 된 TreeView 선택된 된 노드가 모두 표시 되도록 합니다.The following example demonstrates how to change the collapse state of a TreeView so that all the checked nodes are visible. 먼저 모든 노드가 축소 되 고 처리기에 추가 됩니다는 TreeView.BeforeExpand 이벤트입니다.First, all the nodes are collapsed, and a handler is added to the TreeView.BeforeExpand event. 다음에는 모든 노드가 확장 됩니다.Next, all the nodes are expanded. TreeView.BeforeExpand 이벤트 처리기를 지정 된 노드에 검사 되는 자식 노드가 있는지 확인 합니다.The TreeView.BeforeExpand event handler determines whether a given node has child nodes that are checked. 노드가 선택 된 자식에 없는 경우 해당 노드에 대 한 확장 취소 됩니다.If a node does not have checked children, the expansion is canceled for that node. 노드 옆에 더하기 기호를 클릭 하면 일반 노드를 확장을 허용 하기 위해는 TreeView.BeforeExpand 이벤트 처리기가 제거 합니다.In order to allow normal node expansion when the plus sign next to a node is clicked, the TreeView.BeforeExpand event handler is then removed.

이 문제를 처리 하 여 구현할 수도 있습니다는 TreeView.BeforeCollapse 이벤트, 해당 항목의 예제에 설명 된 대로 합니다.This behavior can also be implemented by handling the TreeView.BeforeCollapse event, as illustrated in the example for that topic.

전체 예제를 참조 하세요.를 TreeView.CheckBoxes 참조 항목입니다.For the complete example, see the TreeView.CheckBoxes reference topic.

private:
   void showCheckedNodesButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      // Disable redrawing of treeView1 to prevent flickering 
      // while changes are made.
      treeView1->BeginUpdate();
      
      // Collapse all nodes of treeView1.
      treeView1->CollapseAll();
      
      // Add the checkForCheckedChildren event handler to the BeforeExpand event.
      treeView1->BeforeExpand += checkForCheckedChildren;
      
      // Expand all nodes of treeView1. Nodes without checked children are 
      // prevented from expanding by the checkForCheckedChildren event handler.
      treeView1->ExpandAll();
      
      // Remove the checkForCheckedChildren event handler from the BeforeExpand 
      // event so manual node expansion will work correctly.
      treeView1->BeforeExpand -= checkForCheckedChildren;
      
      // Enable redrawing of treeView1.
      treeView1->EndUpdate();
   }

   // Prevent expansion of a node that does not have any checked child nodes.
   void CheckForCheckedChildrenHandler( Object^ /*sender*/, TreeViewCancelEventArgs^ e )
   {
      if (  !HasCheckedChildNodes( e->Node ) )
            e->Cancel = true;
   }


   // Returns a value indicating whether the specified 
   // TreeNode has checked child nodes.
   bool HasCheckedChildNodes( TreeNode^ node )
   {
      if ( node->Nodes->Count == 0 )
            return false;

      System::Collections::IEnumerator^ myEnum = node->Nodes->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         TreeNode^ childNode = safe_cast<TreeNode^>(myEnum->Current);
         if ( childNode->Checked )
                  return true;

         // Recursively check the children of the current child node.
         if ( HasCheckedChildNodes( childNode ) )
                  return true;
      }

      return false;
   }
private void showCheckedNodesButton_Click(object sender, EventArgs e)
{
    // Disable redrawing of treeView1 to prevent flickering 
    // while changes are made.
    treeView1.BeginUpdate();

    // Collapse all nodes of treeView1.
    treeView1.CollapseAll();

    // Add the checkForCheckedChildren event handler to the BeforeExpand event.
    treeView1.BeforeExpand += checkForCheckedChildren;

    // Expand all nodes of treeView1. Nodes without checked children are 
    // prevented from expanding by the checkForCheckedChildren event handler.
    treeView1.ExpandAll();

    // Remove the checkForCheckedChildren event handler from the BeforeExpand 
    // event so manual node expansion will work correctly.
    treeView1.BeforeExpand -= checkForCheckedChildren;

    // Enable redrawing of treeView1.
    treeView1.EndUpdate();
}

// Prevent expansion of a node that does not have any checked child nodes.
private void CheckForCheckedChildrenHandler(object sender, 
    TreeViewCancelEventArgs e)
{
    if (!HasCheckedChildNodes(e.Node)) e.Cancel = true;
}

// Returns a value indicating whether the specified 
// TreeNode has checked child nodes.
private bool HasCheckedChildNodes(TreeNode node)
{
    if (node.Nodes.Count == 0) return false;
    foreach (TreeNode childNode in node.Nodes)
    {
        if (childNode.Checked) return true;
        // Recursively check the children of the current child node.
        if (HasCheckedChildNodes(childNode)) return true;
    }
    return false;
}
Private Sub showCheckedNodesButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    ' Disable redrawing of treeView1 to prevent flickering 
    ' while changes are made.
    treeView1.BeginUpdate()

    ' Collapse all nodes of treeView1.
    treeView1.CollapseAll()

    ' Add the CheckForCheckedChildren event handler to the BeforeExpand event.
    AddHandler treeView1.BeforeExpand, AddressOf CheckForCheckedChildren

    ' Expand all nodes of treeView1. Nodes without checked children are 
    ' prevented from expanding by the checkForCheckedChildren event handler.
    treeView1.ExpandAll()

    ' Remove the checkForCheckedChildren event handler from the BeforeExpand 
    ' event so manual node expansion will work correctly.
    RemoveHandler treeView1.BeforeExpand, AddressOf CheckForCheckedChildren

    ' Enable redrawing of treeView1.
    treeView1.EndUpdate()
End Sub

' Prevent expansion of a node that does not have any checked child nodes.
Private Sub CheckForCheckedChildren(ByVal sender As Object, ByVal e As TreeViewCancelEventArgs)
    If Not HasCheckedChildNodes(e.Node) Then
        e.Cancel = True
    End If
End Sub

' Returns a value indicating whether the specified 
' TreeNode has checked child nodes.
Private Function HasCheckedChildNodes(ByVal node As TreeNode) As Boolean
    If node.Nodes.Count = 0 Then
        Return False
    End If
    Dim childNode As TreeNode
    For Each childNode In node.Nodes
        If childNode.Checked Then
            Return True
        End If
        ' Recursively check the children of the current child node.
        If HasCheckedChildNodes(childNode) Then
            Return True
        End If
    Next childNode
    Return False
End Function 'HasCheckedChildNodes

설명

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.For more information about handling events, see Handling and Raising Events.

생성자

TreeViewCancelEventArgs(TreeNode, Boolean, TreeViewAction) TreeViewCancelEventArgs(TreeNode, Boolean, TreeViewAction) TreeViewCancelEventArgs(TreeNode, Boolean, TreeViewAction) TreeViewCancelEventArgs(TreeNode, Boolean, TreeViewAction)

지정된 트리 노드, 이벤트가 취소될 지 여부를 지정하는 값 그리고 이벤트를 발생시킨 트리 뷰 작업의 형식과 함께 TreeViewCancelEventArgs 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the TreeViewCancelEventArgs class with the specified tree node, a value specifying whether the event is to be canceled, and the type of tree view action that raised the event.

속성

Action Action Action Action

이벤트를 발생시킨 TreeView 작업 형식을 가져옵니다.Gets the type of TreeView action that raised the event.

Cancel Cancel Cancel Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
Node Node Node Node

확인, 확장명, 축소 또는 선택할 트리 노드를 가져옵니다.Gets the tree node to be checked, expanded, collapsed, or selected.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보