C windows form validating event
My problem is: When I edit stuff in the textboxes, then click the menu to issue "Save", the text from the last text box still hasn't issued its "Validating" method.
There are 2 code paths for validation failure, and in each case we provide the user with an appropriate error message.You now need two validations, one that checks if the entered value is valid, another one that checks if there are no missing values.You get this by accepting an empty string in the Validation event handler.How can I force the validating events to fire when the user clicks "save"?I am trying to better understand how validation works in a Windows Forms application.(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.
Is there a "best practice" document/site for control validation in a Windows Forms application?
Of the many things that are still confusing me, I am unable to find an explanation for the behavior of my dialog when the Ok button Dialog Result property is set to return Dialog Result. Why does setting this property interfere with validation? None seems to change some automatic behavior of the Form class. I think it is easy to use while also fulfilling all the other requirements.
First, add the following code to the Form’s constructor after the Initialize Component method: This is a handy trick to prevent implicit validation of our controls when they lose focus.
You do not have to disable the Form’s Auto Validate property.
In a Win Form I'm doing initial validation in the Form. To make the code short only three fields are shown in the code.