yetaya.blogg.se

Vb.net errorprovider
Vb.net errorprovider





vb.net errorprovider vb.net errorprovider

If errOutOfRange.GetError(TB).Length > 0 Then If TB.TabIndex < FirstTabIndex Then FirstTextBox = TB FirstTabIndex = TB.TabIndex End If End If Next ' See if any control has an error. Dim FirstTextBox As TextBox = Nothing Dim FirstTabIndex As Integer = Integer.MaxValue For Each TB As TextBox In MissingMessages.Keys ' See if the control has an error. For Each TB As TextBox In MissingMessages.Keys ValidateTextBox(TB) Next TB ' Find the first control in the tab order with an error.

vb.net errorprovider

Imports System.ComponentModelImports _Public Class IsRequiredProvider Inherits Implements IExtenderProvider Friend htProvidedProperties As New Hashtable Private MissingMessages As New Hashtable Private mEnabled As Boolean = True Public Sub New(ByVal Container As ) M圜lass.New() Container.Add(Me) End Sub Public Sub New() MyBase.New() InitializeComponent() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private components As Friend WithEvents errOutOfRange As Private Sub InitializeComponent() Me.errOutOfRange = New Me.errOutOfRange.BlinkStyle = .NeverBlink End Sub Private Class ValidatorProperties Public AllowEmptyValue As Boolean = True End Class Private Function GetControlFromHashtable(ByVal ctrl As Control) As ValidatorProperties If htProvidedProperties.Contains(ctrl) Then Return DirectCast(htProvidedProperties(ctrl), ValidatorProperties) Else Dim ProvidedProperties As New ValidatorProperties AddHandler CType(ctrl, TextBox).KeyPress, AddressOf This_KeyPress htProvidedProperties.Add(ctrl, ProvidedProperties) Return ProvidedProperties End If End Function _ Public Property Enabled() As Boolean Get Return mEnabled End Get Set(ByVal Value As Boolean) mEnabled = Value End Set End Property Public Function CanExtend(ByVal client_control As Object) As Boolean Implements IExtenderProvider.CanExtend Return (TypeOf client_control Is TextBox) End Function _ _ Public Function GetAllowEmptyValue(ByVal ctrl As Control) As Boolean Return CType(GetControlFromHashtable(ctrl).AllowEmptyValue, Boolean) End Function _ Public Sub SetAllowEmptyValue(ByVal ctrl As Control, ByVal value As Boolean) GetControlFromHashtable(ctrl).AllowEmptyValue = value End Sub _ Public Function GetIsRequiredMessage(ByVal client_control As Control) As String If MissingMessages.Contains(client_control) Then Return DirectCast(MissingMessages(client_control), String) Else Return Nothing End If End Function _ Public Sub SetIsRequiredMessage(ByVal client_control As Control, ByVal missing_message As String) If MissingMessages.Contains(client_control) Then MissingMessages.Remove(client_control) RemoveHandler client_control.Validating, AddressOf Client_Validating End If If Not (missing_message Is Nothing) Then If missing_message.Length > 0 Then MissingMessages.Add(client_control, missing_message) AddHandler client_control.Validating, AddressOf Client_Validating End If End If End Sub Private Sub Client_Validating(ByVal sender As Object, ByVal e As ) If Not mEnabled Then Exit Sub End If ValidateTextBox(DirectCast(sender, TextBox)) End Sub Private Sub ValidateTextBox(ByVal sender As TextBox) Console.WriteLine("Allow empty value [") e.Handled = True End If End Sub Public Function HasError() As Boolean If Not mEnabled Then Return False End If ' Make sure all controls have been validated. So if you had five TextBox controls on a form, two of them can not be empty, set them up via AllowEmptyValue and IsRequiredMessage, the remaining TextBox controls will not be affected. The ErrorProvider is setup in Sub InitializeComponent that is shown to the right of a TextBox where you have set AllowEmptyValue to False and IsRequiredMessage. IExtenderProvider Interface as shown below. One thought is to create a class that extends all textBox controls via







Vb.net errorprovider