G
Guest
All,
I have a number of controls on a form. Each has its'
own "Validating" event handler in order to make sure the
user enters "valid" data (this can also be used to make
sure the user enters required fields...the data is
initially null/empty, etc..)
Everything works fine if the user attempts to tab away
from a control..the validating event fires and the
appropriate routines validate the user entered data.
HOWEVER, if the user directly presses the "done" button,
closes the form, or "skips" controls (using the mouse)
problems arise...basically I canNOT figure out how to
validate all the controls when the form is
submitted/closed. I would like to do something like this:
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
System.ComponentModel.CancelEventArgs e1;
foreach (Control c in this.Controls)
{
// signal the validating event for control c
// and CANCEL the close Event for the form if the
// control returns e.cancel = true in its' event args
}
}
the problem is I canNOT figure out how to directly call
the controls validating event. I realize I could directly
call my validation routine for each control, however that
would be a real maintenance headache since you would have
to remember to add all future validation routines for any
new controls to the FORM LEVEL validation routine....it
would really be nice to iterate through all the controls
and do the work in one place (i.e. in the controls'
validation event...)
Am I missing something? The real issue deals
with "required" fields and the fact the user could
still "submit" this form (using this event validation
approach) without entering data (unless form level
verification was added)
Thanks,
Fred Iannon
I have a number of controls on a form. Each has its'
own "Validating" event handler in order to make sure the
user enters "valid" data (this can also be used to make
sure the user enters required fields...the data is
initially null/empty, etc..)
Everything works fine if the user attempts to tab away
from a control..the validating event fires and the
appropriate routines validate the user entered data.
HOWEVER, if the user directly presses the "done" button,
closes the form, or "skips" controls (using the mouse)
problems arise...basically I canNOT figure out how to
validate all the controls when the form is
submitted/closed. I would like to do something like this:
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
System.ComponentModel.CancelEventArgs e1;
foreach (Control c in this.Controls)
{
// signal the validating event for control c
// and CANCEL the close Event for the form if the
// control returns e.cancel = true in its' event args
}
}
the problem is I canNOT figure out how to directly call
the controls validating event. I realize I could directly
call my validation routine for each control, however that
would be a real maintenance headache since you would have
to remember to add all future validation routines for any
new controls to the FORM LEVEL validation routine....it
would really be nice to iterate through all the controls
and do the work in one place (i.e. in the controls'
validation event...)
Am I missing something? The real issue deals
with "required" fields and the fact the user could
still "submit" this form (using this event validation
approach) without entering data (unless form level
verification was added)
Thanks,
Fred Iannon