I have a treeview with a list of items that are expandable. When the user checks the checkbox for a parent node, I simulate checking the children nodes. However, the user can check any node (not just parent nodes). I want to distinguish the user's first click, which triggers the node's checkbox event, from the simulated checking of the children node's checkboxes.
I want to distinguish the User's click so I can save the state of the treeview before it changes.
I thought of using a mousedown event, but this doesn't work since the user might click to expand something and I do not want to save the state of the treeview since nothing changed. One way to make this work would be to calculate the dimensions of each checkbox location and then check the mousedown's click coordinates, but I would like to avoid doing this as it would not be easy since I have nested nodes so the check boxes have a few different columns they could be.
Another way to think of this is I want to turn groups of events into actions. So one action would represent the User's first action, and all the simulated actions that followed until control is returned to the user.
Another thought, maybe I could do something with window focusing or control. For instance if the window is not focused while simulating, I could just save on the focus change if it would occur during a User's action of checking a tree node's checkbox.
Additional info
The simulated checkbox clicks are invoked by code such as:
e.Node.Checked = false;
This triggers the event: private void tree_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
When a user clicks a node, this AfterCheck event triggers. I want to save the state of the tree here. But inside the AfterCheck event, there are cases that check other nodes causing the AfterCheck event to trigger again n times, but this time the check for the checkbox was simulated.
Systems.Windows.Forms.TreeView is the sender object in all cases.