As a follow up to my previous post about enhancing the validation controls within Windows Forms, there might be times when you would like to manually invoke the “Validating” event of a control.For example, you might want to have a routine that fires on the form's “Closing” event or a data save method to loop through all the controls on your form and validate them independently to ensure that all controls are valid.This may come in the form of simply checking if there is an entry for a field, such as a name or a more complex task such as validating an email address.Thankfully Win Forms has built in mechanisms to help facilitate data validation.(See the figure below.) You don't want to perform validation if the user presses the Cancel or Help buttons, so you set their Causes Validation properties to False.The default value for this property is True, so you don't have to modify it for the other controls.In this chapter, we'll look at two facets of dealing with problems in . First, we'll demonstrate the programming that you can do to handle errors, allowing the user to make corrections when something goes wrong.
In such cases, you can force the controls in the support library to behave more closely to the original VB6 controls by setting the VB6Config.
Back Color = vb Yellow End Sub Private Sub Text1_Lost Focus() Text1.
Back Color = vb White End Sub Private Sub Text1_Validate(Cancel as Boolean) Cancel = (Text1. In some applications, however, the code in the Text1_Lost Focus method might depend on some variable that has been set in the Validate event.
A network link to a server might fail just as you're transferring data.
Or perhaps you simply didn't allow for a particular rare circumstance in your code. NET Framework offers a robust set of tools for dealing with these unexpected problems.
Consistent use of these techniques will help make your applications more robust and reliable.