Error provider problems

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writing a windows application based on a set of generic user controls
that I have developed.

I have a user control called "ctlInputText" that has a label, textbox and
error provider. The error provider is used to ensure that the text box is
completed. There is a property that can be set in the control that disables
the validation so that the control can also be used for situations where the
text box is optional.

My problem is this. I have put 2 of these controls onto a dialog form. The
first control does not require validation, but the second control does. If I
click OK on the form when the focus is on the control that does not require
validation then the dialog closes WITHOUT doing validation on the second box
- this is ofcourse not what I want.

How do I get the form to validate each control when I click the OK button,
not just the control that has focus. Alternatively is there a way that I can
validate the whole form when it is loaded, causing all of the controls that
require dataentry to be flagged with the little icon thing?

Thanks in advance


Huw
 
Yes, here is the code i am using:

private void ctlTextBox1_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (mvalRequired)
{
string error = null;
if (this.ctlTextBox1.Text.Length==0)
{
error = mvalRequiredErrorText;
e.Cancel=true;
}
this.errorProvider1.SetError((Control)sender,error);
}
}

mvalRequired is used to dtermine if validation is to be performed or not.
mvalRequiredErrorText holds the text that I want to use in the tooltip
 
Hp,

When I see this, is it than not better to set the validating event of the
control dynamicly than the mvalRequiered?

ctlTextbox1.Validating += new
System.ComponentModel.CancelEventHandler(this.ctlTextBox1_Validating);

Just an idea?

Cor
 
Back
Top