This site uses cookies. By continuing, your consent is assumed. Learn more

99.4fm shares

Validating user input in windows forms c#

opinion

By using our site, you acknowledge that you have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service.

NET provides a mechanism to...

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.

NET provides a mechanism to...

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.

The Validating event provides the hook to perform the validation and ErrorProvider gives a nice consistent approach to providing the user with feedback on any error conditions. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of serviceprivacy policy and cookie policyand that your continued use of the website is subject to these policies.

C Validating input for textbox on winforms Ask Question.

News feed