I want to check what the user is writing in a textbox before I save it in a database. What is the best way to do this? 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.
There are many ways to validate your TextBox.
You can do this on every keystroke, at a later time, or on the Validating event. The Validating event gets fired if your TextBox looses focus. When the user clicks on a other Control, for example.
If your set e. ActiveControl property to the current form, focus events occur in the following order. When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:.
You can use the ErrorProvider to visualize that your TextBox is not valid. With WinForms you can use the ErrorProvider in conjunction with the Validating event to handle the validation of user input.
C Validating input for textbox on winforms Ask Question.