Custom Error Provider (with Error count)
The Error Provider Component used on Windows Forms is a very useful way of displaying the errors on the form, however its missing one small piece of information; the number of errors that are currently on the form. This custom error provider fixes that problem and allows you, among other things, to check the number of errors on the form before performing some action.
i.e. If Me.ErrorProvider.HasErrors = False then
It's proved very useful in a project I'm helping out on.
-------------------------------------------------------------------------------------------------------------------
Public Class ErrorProviderWithCount
Inherits System.Windows.Forms.ErrorProvider
Dim controlsWithErrors As New List(Of Windows.Forms.Control)
Public Sub New(ByVal components As System.ComponentModel.IContainer)
MyBase.New(components)
End Sub
Public Shadows Sub SetError(ByVal control As Windows.Forms.Control, ByVal value As String)
MyBase.SetError(control, value)
If String.IsNullOrEmpty(value) Then
If controlsWithErrors.Contains(control) = True Then
controlsWithErrors.Remove(control)
End If
Else
If controlsWithErrors.Contains(control) = False Then
controlsWithErrors.Add(control)
End If
End If
End Sub
Public ReadOnly Property Count() As Integer
Get
Return controlsWithErrors.Count
End Get
End Property
Public ReadOnly Property HasErrors() As Boolean
Get
Return controlsWithErrors.Count > 0
End Get
End Property
End Class