I'm developing a configuration dialog that uses a tree control and a tabbed pane and I'm having problems with the event timing. The tree control shows the structure of connected hardware and the tabbed pane shows the configuration for the selected node. The tree control is used because a tabbed pane cannot have additional tabs created during run-time, and the connected hardware varies from installation to installation. Rather than writing a hard-coded tabbed pane for every deployment, I'm using a flexible class structure that allows an "m x n" configuration--m zones with n channels per zone, but n is variable by zone. Selecting a node in the tree populates the appropriate tab with the node's values. The number of zones is limited to the number of configured system displays (discrete monitors) and the total number of channels is limited to the number of installed A/D channels. To capture the configuration data, each control in the tabbed pane has a "value changed" event, which sets the value to the appropriate element in the class.
Now that you know what it's supposed to do, here's the problem: it only works if you don't click the tree after changing a value. E.g. if you type in a new "scale" and then click somewhere else on the tabbed pane, the value is correctly associated with the node. If you click on a different node in the tree before exiting the field, the value is assigned to the clicked node instead. I've looked at the timestamps for the events and the field's "value changed" event fires first, so the tree's value should still be the original node. Instead, the tree seems to update before the field's "value changed" event is handled, even though the field's event was fired first. I'm reading the value of the tree inside the event handler for the field, but there's no way to get the "previous" value since the field control is in the tabbed pane.
So where do I go from here? Is this a legitimate race condition, or am I just not processing the events properly? I'd prefer not to post the code since it's rather cumbersome with all of its dependencies, but I can try and make a simple example.