C# WinForms ErrorProvider Control

后端 未结 5 1169
暗喜
暗喜 2020-11-27 20:56

Does anyone know if there is a way to get a list of controls that have the ErrorProvider icon active. ie. any controls that failed validation. I\'m trying to avoid looping

5条回答
  •  悲&欢浪女
    2020-11-27 21:35

    Just make the errorprovider as a Global variable rather than local variable

    public partial class MainForm
     {
    
        ErrorProvider errorProvider1 = new ErrorProvider();
        void Validate_Working()
        {
        errorProvider1.SetError(textbox1, "textbox is empty");
        errorProvider1.Clear();
        }
    
    
     }
    

    from

    public partial class MainForm
     {
    
        Void Validate_NotWorking()
        {
        ErrorProvider errorProvider1 = new ErrorProvider();
        errorProvider1.SetError(textbox1, "textbox is empty");
        errorProvider1.Clear();
        }
    
    
     }
    

    This should fix your problem, because probably you might have been removing your errors from another method such as btnCancel_click. This worked for me :)

提交回复
热议问题