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.
So before saving data, I want to validate whether all the required fields are filled (Text Boxes) by the user. I would rather use a generic function that would be passed each control on the form and based on the type of the control, separate validation logic would be written.
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.
I've read something about Validating Events, but I am not sure how can I use them. Validating Event When you change the focus by using the keyboard (TAB, SHIFT TAB, and so on), by calling the Select or Select Next Control methods, or by setting the Container Control.
Active Control property to the current form, focus events occur in the following order Enter Got Focus Leave Validating Validated Lost Focus When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order: Enter Got Focus Lost Focus Leave Validating Validated event provides the hook to perform the validation and Error Provider gives a nice consistent approach to providing the user with feedback on any error conditions.
though: The Error Provider component does not provide built-in support for accessibility clients.
Validation Text Box also supports functions that generate regular expressions.
Having a generating function enables you to write much more dynamic Web applications.
For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section, and the "Message Deadlocks" section of the "About Messages and Message Queues" topic in the MSDN library at
The following code example uses the derived class Text Box and validates an e-mail address that the user enters.
When there are input views, UIKit might swap out the keyboard even when a text object is first responder, and it might show a keyboard-like input view on the developer's behalf for non-text objects.
The sequence of messages that both text views and text fields send to their delegates is as follows: provided by the UIKit framework, you usually need to configure text fields and text views before they’re displayed.
If no other text object is selected, the system hides the keyboard; if, on the other hand, the user selects another text object, it becomes first responder and the keyboard for that object is displayed.