none
Error Provider Not Showing Error [!] RRS feed

  • Question

  • I have used errorprovider in my winform, When i go to the text box and tab out of it it does not give any warning or anything...
    First i m just trying to check for an empty field. 
    I have set the causes validation property => true

    also  selected "txtstdname_validating"(my textbox) property from the properties.

    Code is as follows:

    private void txtstdnm__validating(object sender, CancelEventArgs e)
            {
                if(txtstdnm.Text.Trim() == "" )
                {
          errorProvider1.SetError(txtstdnm, "Name is required");
          e.Cancel = true;
        return;
      }    
      // Name is Valid
                errorProvider1.SetError(txtstdnm, "");
            }

    Now what else do i need to do.
    i have checked almost all forums. Still don know what am i missing.


    • Edited by osmniv Friday, September 12, 2014 11:00 AM
    Friday, September 12, 2014 10:59 AM

Answers

  • Did you just paste the code or created the event though the interface ?

    In the designer (auto-generated) code there should be this line:

    this.txtstdnm.Validating += new System.ComponentModel.CancelEventHandler(this.txtstdnm_Validating);

    Or you can do it in your form load or something...

    Friday, September 12, 2014 11:04 AM

All replies

  • Did you just paste the code or created the event though the interface ?

    In the designer (auto-generated) code there should be this line:

    this.txtstdnm.Validating += new System.ComponentModel.CancelEventHandler(this.txtstdnm_Validating);

    Or you can do it in your form load or something...

    Friday, September 12, 2014 11:04 AM
  • Hi osmniv,

    Please insert breakpoints to see whether textbox__validating event has been fired when you tab between controls. From here we may get some info:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating(v=vs.110).aspx

    When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl.ActiveControl property to the current form, focus events occur in the following order:

    1. Enter

    2. GotFocus

    3. Leave

    4. Validating

    5. Validated

    6. LostFocus

    Now it seems the event hasn't been triggered, that is the problem. What if you manually trigger this event?

    Regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, September 16, 2014 8:22 AM
    Moderator