Here's another approach (perhaps too brute force, but...). For some courseware I was writing for AppDev (www.appdev.com) , I created a custom control that emulates the behavior of the RequiredFieldValidator, for a TextBox control. Perhaps this will meet your needs? It is currently limited to a text box, but you could easily inherit from the base Control class and handle things a bit differently to expand it. THe point of this particular example was to be as simple as possible, but it might give you some ideas:
' From TextBoxRequired.vb: Imports System.ComponentModel
Public Class TextBoxRequired Inherits System.Windows.Forms.TextBox
Private mstrInitialValue As String
' If the control's value equals its initial ' value, it's not valid. Normally, the ' initial value is an empty string--therefore, ' when validating the control, if the current ' value is the same as the initial value ' (that is, it's still empty) then the ' control isn't valid. <Category("Behavior"), _ Description("Specifies the value the control " & _ "must differ from in order to validate.")> _ Public Property InitialValue() As String Get Return mstrInitialValue End Get Set(ByVal Value As String) mstrInitialValue = Value End Set End Property
' Provide a way to determine if the control's ' text is valid, even if the client has turned ' off the CausesValidation property for the control. <Browsable(False)> _ Public ReadOnly Property Valid() As Boolean Get Return IsValid() End Get End Property
Private Function IsValid() As Boolean Return Me.Text <> mstrInitialValue End Function
Protected Overrides Sub OnValidating(ByVal e As CancelEventArgs) e.Cancel = Not IsValid() MyBase.OnValidating(e) End Sub End Class
|