Data Validation

You should never trust your users. I don't mean you can't trust them to pay (a separate issue that I won't go into here); I mean you can't trust the data that your users enter. They may not give you all the data that you need, or they may not give you data in the correct format. List boxes, radio buttons, and all the other controls that give users choices do so to make sure that they provide data in the correct format. However, sometimes you need to validate free-form data entry, such as what a user types into a text box. For that, you handle a control's Validating event:

					void applicantNameTextBox_Validating(object sender, CancelEventArgs e) { // Check for existence of application name if( applicantNameTextBox.Text.Length == ...

Get Windows Forms Programming in C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.