Rousseau10
Programmer
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.
Here is the code for one of the button controls that repopulates TextBox.Text values that causes ErrorProvider1 to stop working correctly.
Thanks for any Help!
Rousseau10
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:
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:
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