I have the following TextBox Validating event (just test validation data entry to prove working method):
private void txtPart_Validating(object sender, CancelEventArgs e)
{
string error = null;
if (txtPart.Text != "L")
{
error = "Validation failed - Part Number";
e.Cancel = true;
errorProvider2.SetError((Control)sender, error);
}
}
The Validation works fine. However, I have also included the following code during initialization to stop the Validation events if I click a Cancel button.
this.btnCancel.CausesValidation = false;
this.CausesValidation = false;
If I click the Cancel button it resets all TextBoxes to "" and then tries to set focus on the first TextBox. When I click the Cancel button the clearing of the TextBoxes happens but the Validation event is raised for the TextBox that has/had focus. I get trapped on the last TextBox.
Everything I have read indicates I am doing this correctly, but the reality is I must not be as the Cancel button does not work as intended.
Any guidance will be greatly appreciated.
Regards,
Lance