I am new to verification. I have a winform C # project that I want to validate the form before closing. However, I want this check to be performed when I click the button. Therefore, I have an event that fires for this like this:
if (!this.ValidateChildren())
{
MessageBox.Show("Validation failed");
}
else
{
MessageBox.Show("Validation passed with flying colours. :)");
this.Close();
}
I only want to close the form if the verification was successful. Easy enough. However, I do not want the validation to be performed when text fields lose focus, only when the entire form is validated.
Every control that I want to test, I registered a check event. They use "e.Cancel = true"; to cancel the check. I use the ErrorProvider class for visual maintenance.
So, the main question is: what is best suited for checking a specific set of controls only when I want, and not when the focus is lost from the control?
EDIT: Currently, as a job, I have a method that turns the CausesValidation property on and off. I default everything to prevent CauseValidation, letting them all before using this event to validate the entire form and turn them off again.
I really do not see this as an ideal approach. Are there any other “elegant” solutions?
Imreg source
share