TreeViewCancelEventArgs TreeViewCancelEventArgs TreeViewCancelEventArgs TreeViewCancelEventArgs Class

定義

BeforeCheck コントロールの BeforeCollapseBeforeExpandBeforeSelect、および TreeView の各イベントのデータを提供します。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 'showCheckedNodesButton_Click

' 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 'CheckForCheckedChildren

' 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)

適用対象

こちらもご覧ください