Data Validation

You should never trust your users. We don't mean you can't trust them to pay (a separate issue that we won't go into here). We 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:

 Sub applicantNameTextBox_Validating(object As Sender, _ e As CancelEventArgs) _ Handles applicantNameTextBox.Validating ' Check for existence of application ...

Get Windows Forms Programming in Visual Basic .NET 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.