Previous Page
Next Page

Chapter 22 Quick Reference

To

Do this

Validate the contents of a single control.

Use the Validating event method. For example:

private voidtitleValidating(
object sender, CancelEventArgs e)
{
    if (!checkTitleAndGender()
)
    {
        e.Cancel = true;
    }
}

Allow the Validating event to be raised.

Set the CausesValidation property of all controls on the form to true.

Validate the contents of multiple controls or an entire form.

Use form-level validation. Create a method that validates all the data on the form. Call it when the user indicates that data input is complete, such as when the user clicks the Save Customer button.

Indicate which values are in error and display error information in a non-intrusive manner.

Use an ErrorProvider control. Call the SetError method of the ErrorProvider control to display an error icon and record an error message that can be displayed as a ToolTip when the user holds the mouse over the error icon.

Display messages in a status bar at the base of a form.

Add a StatusStrip control to the form. Add a ToolStripStatusLabel control to the StatusStrip. Set the Text property of the ToolStripStatusLabel control to the message you want to display at runtime.


Previous Page
Next Page