TreeView.BeforeCheck イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TreeView.BeforeCheck イベントの意味・解説 

TreeView.BeforeCheck イベント

ツリー ノードチェック ボックスオンにされる前に発生します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event BeforeCheck As
 TreeViewCancelEventHandler
Dim instance As TreeView
Dim handler As TreeViewCancelEventHandler

AddHandler instance.BeforeCheck, handler
public event TreeViewCancelEventHandler BeforeCheck
public:
event TreeViewCancelEventHandler^ BeforeCheck {
    void add (TreeViewCancelEventHandler^ value);
    void remove (TreeViewCancelEventHandler^ value);
}
/** @event */
public void add_BeforeCheck (TreeViewCancelEventHandler
 value)

/** @event */
public void remove_BeforeCheck (TreeViewCancelEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

ユーザーチェック状態を変更したときに TreeNode のすべてのツリー ノード更新するコード例次に示します。このコードは、TreeNode オブジェクトの TreeNodeCollection を持つ TreeView が、Form配置されていることを前提としています。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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeView クラス
TreeView メンバ
System.Windows.Forms 名前空間
TreeView.CheckBoxes プロパティ
OnBeforeCheck
TreeView.AfterCheck イベント
OnAfterCheck



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

TreeView.BeforeCheck イベントのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeView.BeforeCheck イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS