INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

winforms errorprovider will not work after programatically changing data values in textboxs

winforms errorprovider will not work after programatically changing data values in textboxs

winforms errorprovider will not work after programatically changing data values in textboxs

(OP)
Hi all,

WinForms errorProvider will not work after programmatically changing data values in textboxes
I tried ErrorProvider1.Clear() but did not help. If it is a UI change by user, there is no problem with ErrorProvider1.
I tested after program changes code that it still runs through the txtAPU_Validated(object sender, EventArgs e) code correctly.
But no invalid icon next to field(s) appears.

So this code is my 'long way around the barn' work-around,, I had to use a temporary work around using a Boolean variable to change of textbox.text data value was changed in code, then dragged on and using errorProvidor3.

CODE --> c#

private void txtAPU_Validated(object sender, EventArgs e)
{
    bool bTest = txtAPUIsValid(@"(?i)^\d[0-9]?.\d{0,3}$");
    if (!progChangedText)//A.R.S. 7-12-15 - bool to check if the program changed the code (not the User)
    {

        if (bTest == true)
        {
            this.errorProvider1.SetError(txtAPU, "Field must contain only numbers and a decimal point. " +
                                                 "Up to 2 numbers before decimal point and up to 3 numbers trailing it.");
        }
        else
        {
            this.errorProvider1.SetError(txtAPU, "");
        }
    }
    else
    {
        if (bTest == true)
        {
            this.errorProvider3.SetError(txtAPU, "Field must contain only numbers and a decimal point. " +
                                                 "Up to 2 numbers before decimal point and up to 3 numbers trailing it.");
        }
        else
        {
            this.errorProvider3.SetError(txtAPU, "");
        }
    }

private bool txtAPUIsValid(string _rgxPattern)
{
    bool testBool = true;
    RgxPattern = _rgxPattern;
    Regex x;
    x = new Regex(RgxPattern, RegexOptions.IgnorePatternWhitespace);

    if (x.IsMatch(txtAPU.Text))
    {
        return false;
    }
    return testBool;
}
} 

Here is the code for one of the button controls that repopulates TextBox.Text values that causes ErrorProvider1 to stop working correctly.

CODE --> c#

private void btnResetOriginalData_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear(); errorProvider2.Clear(); errorProvider3.Clear();
            int i = 0;
            foreach (Control ctl in this.tlpTextBoxes.Controls)
            {
                if (ctl is TextBox)
                {
                    TextBox textBox = (TextBox)ctl;//casting Control Type to textbox
                    textBox.ResetText();
                    textBox.Text = strListControlValues[i];
                    i++;
                }
            }
        } 

Thanks for any Help!
Rousseau10

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close