Hi,
Is there any way to force the validating event to fire on a control prior to a tab switch so the tab switch can be cancelled? This is how a normal tab control works. We seem to be receiving the validating event after the tab switch occurs which is nasty if validation fails and message box opens. Also, if i open 2 tabs side by side using the grouping feature, I receive 2 validation events on the control losing focus when I select the other tab. If validation fails then focus remains in the control with invalid data but the other tab is selected. Is there anyway to get validation to work like a regular tab control, or turn validation off altogether?
Thanks,
Bill
This actually looks like a bug with the .NET Form. If you remove the UltraTabbedMdiManager, you can enter invalid input on one mdi child, then select another mdi child and the other mdi child will be selected before the Validating event is fired. The UltraTabbedMdiManager just controls the layout of Forms in the mdi parent and does not get involved in activation. You can work around this by by calling Activate() on the mdi child before showing your message box in the Validating event. Also, you can turn off validation by setting CausesValidation on the mdi child Forms to False.
Thanks Mike, I don't have control over what goes on in the validating event of every control in our system so I can't call activate. Do you know of a way to trigger the validating event during the TabSelecting event so I can cancel the tab change if the validation failed?
Thanks again,
In that case, you can call ValidateChildren on the ActiveMdiChild on the parent form. If it returns False, cancel the TabSelecting event.
perfect, I was not aware of that method.
we are having the same problem and Bills answers works fine how can I prevent the validation when the user closes the Parent form?
regards
Stefan
You might be able to set a flag in the FormClosing of the parent and bypass your validating code when the flag is set.
that is not possible because validating fires before formclosing.
Sorry about that. In that case, it looks like you may only be able to do this if you have unmanaged code rights. You can override the WndProc in your mdi parent Form. If the message coming in it WM_CLOSE (0x0010), the Form is about to close and you can set your flag.