(Try my example with and without that line, to see what I mean.) My problems from yesterday (it would appear) stem mostly from not understanding the Validate Children method and from my setting the Ok button Dialog Result property to Dialog Result. I apologize in advance for how long this question ended up being.
If I could show you all the real application, it would make more sense as to why this is so important.
In this case, we simply clear any error messages in the error provider.
The Name textbox works very similarly but we don’t have quite as elaborate validation logic.
But the latter is not well supported by Winforms, you need code.
I know this is somewhat late, but I would add one more thing to Hans answer.
After the validating event returns without being cancelled, meaning we have valid user input, then the validated event will be raised.
Anyway, thanks for helping this old dog learn a new trick. to prevent the user from moving away from the text box.
The answer was to create one Error Provider for each control needing validation (vs. Which means that she can only get to the OK button when the text box was validated to be okay.
Create a textbox event Validated and move the m_Error Provider. When validating completes (e.cancel == false) the validated event is fired.
I want to check what the user is writing in a textbox before I save it in a database. I guess I can always write some ifs or some try-catch blocks, but I was wondering if there's a better method.