By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Error provider problems

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
HpLloyd,

Do you use the validating event?

Cor
Nov 16 '05 #2

P: n/a
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

"Cor Ligthert" wrote:
HpLloyd,

Do you use the validating event?

Cor

Nov 16 '05 #3

P: n/a
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.ctlT extBox1_Validating);

Just an idea?

Cor
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.