ErrorProvider component only sets for last control...why?

Here is my class:

public class superComboBox : ComboBox
{
      private bool is_required = false;

      private ErrorProvider ctrlErr = new ErrorProvider();
      private string err_msg = "";
            
      public bool Required
      {
            // Retrieves the value of the private variable is_required
            get
            {
                  return is_required;
            }
            // Stores the selected value in the private variable is_required
            set
            {
                  is_required = value;
            }
      }
            
      public string ErrorMessage
      {
            // Stores the selected value in the private variable is_required
            set
            {
                  err_msg = value;
                  ctrlErr.SetError(this, err_msg);
            }
      }
}

And here is how I'm using it on my page:

private bool validateComboBox(superComboBox ctrlToTest)
{
      if (ctrlToTest.Required == true)
      {
            if (ctrlToTest.SelectedIndex == 0)
            {
                  ctrlToTest.ErrorMessage = "The\"Select...\" option is not a valid choice.";            
                  return false;
            }
      }

      return true;
}

Let's say I have 3 drop-down controls on my form.  If all 3 controls fail validation, I'd expect to see the red splat besides each control.  But, it only appears on the last control and I can't figure out why.  I know that you can't dynamically set the name for a error provider control so that's why I thought putting it in a class would help.  To no avail though, so help me out people :-)
LVL 13
jrramAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
The ErrorProvider component has a one-to-one relationship between a control and an error condition.  If you have 3 controls, then you need 3 error providers.

Bob
jrramAuthor Commented:
That's strange, cause it works if I use it on multiple panel controls.
Bob LearnedCommented:
What do you mean by "it works if I use it on multiple panel controls"?

Does that mean that you have one error provider, and multiple controls with red error conditions?

Bob
jrramAuthor Commented:
I got it to work.  All I had to do is declare my ErrorProvider declaration at the beginning of the program and it worked.  I think the problem before was I kept re-defining the component.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;

namespace ResizeMe
{
      /// <summary>
      /// Summary description for part1.
      /// </summary>
      public class actSurvey : System.Windows.Forms.Form
      {
            private System.Windows.Forms.Button cancel;
            private System.Windows.Forms.TabPage tabPage1;
            private System.Windows.Forms.TabPage tabPage2;
            private System.Windows.Forms.Panel panel2;
            private System.Windows.Forms.Panel panel1;
            private System.Windows.Forms.Panel processPanel;
            private System.Windows.Forms.TabControl surveyBook;
            private System.Windows.Forms.Button saveSurvey;
            private System.ComponentModel.IContainer components;

            private ErrorProvider formErrorHandler = new ErrorProvider();

            private bool validateTabs()
            {
                  int failedControls = 0;

                  foreach(TabPage tp in surveyBook.TabPages)
                  {
                        foreach(Control ctrl in tp.Controls)
                        {                                    
                              if (ctrl.GetType() == typeof(superTextBox))
                              {
                                    if (!validateTextBox((superTextBox) ctrl)) failedControls+=1;
                              }
                              else if (ctrl.GetType() == typeof(superComboBox))
                              {
                                    if (!validateComboBox((superComboBox) ctrl)) failedControls+=1;
                              }
                              else if (ctrl.GetType() == typeof(radioPanel))
                              {
                                    if (!validateRadioPanel((radioPanel) ctrl)) failedControls+=1;
                              }
                        }
                  }

                  return failedControls == 0 ? true :  false;
            }

            private bool validateComboBox(superComboBox ctrlToTest)
            {                        
                  formErrorHandler.SetIconAlignment(ctrlToTest, ErrorIconAlignment.TopRight);
                  formErrorHandler.SetError(ctrlToTest, String.Empty);

                  if (ctrlToTest.Required == true)
                  {
                        if (ctrlToTest.SelectedIndex == 0)
                        {                        
                              formErrorHandler.SetError(ctrlToTest, "The\"Select...\" option is not a valid choice.  Please choose another option!"
                                                + "\n\nMore Info: " + ctrlToTest.MoreInfo);
                              
                              return false;
                        }
                  }

                  return true;
            }

      }
}
ee_ai_constructCommented:
Question answered by asker or dialog deemed valuable.
Closed, 250 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.