I'm using an ErrorProvider with a code looking like that:
private void textBoxLocation_Validating(object sender, CancelEventArgs e)
{
if (!ValidateLocation())
{
e.Cancel = true;
}
}
This specific textBox was meant for a user to enter a certain path by either typing it directly to the textBox, or by pressing a "browse" button which opens a FileDialog and then the path is copied to the textBox.
The problem is that when the user types something directly to the text box which is not validated, the e.Cancel = true; is called which makes the textBox not to lose focus, but then I can't even press the browse button to select a path. Not only that, I can't even close the program.
How can this be fixed?
Presumably you're setting the text of the
ErrorProviderinValidateLocation. In that case, you really just don't want to usee.Cancelhere because it was meant to do exactly what it's doing. Keep the control from losing focus.That would make sense in a scenario where it was an input error.
So, in short, it just doesn't make sense for you to use
e.Cancelhere.