Please see our comments to the question. Most likely, you mean
System.Windows.Forms.TreeView
.
If so, you can capture the event of changing checked state of your parent node by handling one of both of these events:
TreeView.AfterCheck Event (System.Windows.Forms)[
^],
TreeView.BeforeCheck Event (System.Windows.Forms)[
^].
The check of other nodes is performed using the property
System.Windows.Forms.TreeNode.Checked
:
TreeNode.Checked Property (System.Windows.Forms)[
^].
You will need the node which is about to change or changed its check state. The reference to this node will be passed to your event handler via the event arguments parameter:
TreeViewEventArgs Class (System.Windows.Forms)[
^],
TreeViewEventArgs.Node Property (System.Windows.Forms)[
^].
You should be extra careful here, to avoid infinite
recursion. When you programmatically change the checked state in your event handler, it will eventually call the same event handler. So, you need different action on the change of this state as an immediate result of the user click and as a result of your programmatic change.
Again, look at this page I already referenced above:
TreeView.AfterCheck Event (System.Windows.Forms)[
^].
See the "Remark" section which warns you about this situation. See also the code sample; pay attention for the comment "The code only executes if the user caused the checked state to change". In your code, you should also take care of that.
—SA