Control.Validating event

"Nassar, Anthony" <[email protected]> Thu, 4 Oct 2007 14:07:33 -0400
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
I'm somewhat puzzled over what the CancelEventArgs argument to this
event handler is actually supposed to accomplish. Yes, I've read the
documentation. I have a number of composite controls in docking panels,
and I'd like to prevent the user, somehow, from setting focus to another
control in a different docking panel if he's put the model into an
invalid state from the current panel. However, a mouse click will cause
events the fire in this order: GotFocus, LostFocus, Leave, Validating,
Validated. Now the user can edit stuff in other controls, drag and drop,
whatever. It seems like I have no choice but to have the parent control
maintain the validity of the entire model, and therefore find the
control the user *was* working on and set the focus back to it. I could
do this in a clean, OO way, but in essence I'm grabbing the mouse and
putting it back where I want it to be, which seems like a horrible,
hacky, pre-.NET tning to do.

What exactly is the semantics of "Validate," if I can't cancel it in any
meaningful sense? The new control will get focus before the invalid
control loses focus, which makes sense in terms of Win32 messages, but
does *not* make sense in the context of my application, where a
composite control with invalid state should be able to keep the user's
attention as long as it needs to.