Apr 1, 2010 at 1:48 PM
Edited Apr 1, 2010 at 2:07 PM
Currently the Validation Block winforms integration will automatically cancel any validation if it fails, preventing progress to the next item of the form or changing focus. I've come across a number of scenarios where I would like the user to be able to
proceed, just having the errors displayed, and progress prevented on clicking OK or Submit, but this is not possible with the current configuration as focus change is prevented. Also - the cancel button cannot be clicked while validation fails, which feels
I have made some changes myself but would like to submit them as a feature request so that they can be used with the pre-compiled and installed blocks.
In the ValidationProvider, add a new property (Defaulted to false):
public bool PreventRefocus
///Flag indicating whether Focus should be
/// prevented when validation fails
Then, in the ValidatedControlItem, where the base control Validated event is handled, change the OnValidating method as follows:
void OnValidating(object source,
e.Cancel = (validationProvider.PreventRefocus && !IsValid)
This simple change will enable you to switch between holding up progress on control validation, and allowing it to continue,
simply by setting a flag in the validation provider.
Any thoughts On this approach?
I think your requirement can be achieved without modifying the source code. Simply set the
AutoValidate property of your windows form containing your error provider to
"Also - the cancel button cannot be clicked while validation fails, which feels very klunky"
You can resolve this by making sure that the Perform Validation on <validationProviderName> is set to false or just simply set the CausesValidation property to False.
Global Technology & Solutions