Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. int errorCount;
  2. void SetError(Control c, string message)
  3. {
  4. if (message == "")
  5. errorCount--;
  6. else
  7. errorCount++;
  8. errorProvider.SetError(c, message);
  9. }
  10.  
  11. bool IsValid()
  12. {
  13. foreach (Control c in errorProvider1.ContainerControl.Controls)
  14. if (errorProvider1.GetError(c) != "")
  15. return false;
  16. return true;
  17. }
  18.  
  19. public static class ErrorProviderExtensions
  20. {
  21. private static int count;
  22.  
  23. public static void SetErrorWithCount(this ErrorProvider ep, Control c, string message)
  24. {
  25. if (message == "")
  26. {
  27. if (ep.GetError(c) != "")
  28. count--;
  29. }
  30. else
  31. count++;
  32.  
  33. ep.SetError(c, message);
  34. }
  35.  
  36. public static bool HasErrors(this ErrorProvider ep)
  37. {
  38. return count != 0;
  39. }
  40.  
  41. public static int GetErrorCount(this ErrorProvider ep)
  42. {
  43. return count;
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement