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
Published Friday, October 12, 2007 4:22 PM by dsmyth
Filed under:

Comments

No Comments

The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.