G
Guest
How can I loop through all the controls on the form, and for certain types of
controls, access the custom properties. For example, I've created a custom
textbox for name fields. It has a property called InvalidData that I turn on
during the validating event if the data is not valid.
Here's my code that loops through all the records:
private bool AnyFieldErrors()
{
// Clear the error message fields
bool _anyErrors = false;
// Perform the validate event for each field on the screen
foreach (Control control in GetAllControls() )
{
if (control.CausesValidation == true)
{
control.Focus();
if (!this.Validate() )
{
string CName = control.Name;
string CType = control.GetType().ToString();
if (CType == "WS.Windows.Forms.NameTextBox")
{
if (control.InvalidData) // How do I refer to a custom type?
{
_anyErrors = true;
}
}
}
}
}
return _anyErrors;
}
controls, access the custom properties. For example, I've created a custom
textbox for name fields. It has a property called InvalidData that I turn on
during the validating event if the data is not valid.
Here's my code that loops through all the records:
private bool AnyFieldErrors()
{
// Clear the error message fields
bool _anyErrors = false;
// Perform the validate event for each field on the screen
foreach (Control control in GetAllControls() )
{
if (control.CausesValidation == true)
{
control.Focus();
if (!this.Validate() )
{
string CName = control.Name;
string CType = control.GetType().ToString();
if (CType == "WS.Windows.Forms.NameTextBox")
{
if (control.InvalidData) // How do I refer to a custom type?
{
_anyErrors = true;
}
}
}
}
}
return _anyErrors;
}