how to invoke the e argument in Validating Sub ?

loyal

Centurion
Joined
Jul 29, 2003
Messages
102
how to invoke the e argument in Validating Sub ?

well I have a text box that used ErrorProvider in

Validating Event I want to cancel the validating

by invoke the sub and send false to the( e ) argument

But how ?

Here is the code

If IsNumeric(txtName.Text) Then
ErrorProvider1.SetError(txtName, "Please Enter a string Value")
e.Cancel = True

Else
ErrorProvider1.SetError(txtName, "")

End If




:cool:
 
If im understanding correctly what you want to do cant be done. You cant pass in a boolean value in place of System.ComponentModel.CancelEventArgs, and you cant change the value like that because you are setting it to true anyway. You could make another boolean value that will be for example set to true and if its true then change e.Cancel to false.
All of this is based on assumption :).
 
Actually, what you need to do is create a CancelEventArgs, not a boolean, and pass that in.

Visual Basic:
Dim args As New System.ComponentModel.CancelEventArgs()
args.Cancel = False

txtName_Validating(Nothing, args)
 
the first work perfectly but the second I don't know why

here's the applcation see if there's a mistake I have done

here's the code
Visual Basic:
Dim b As Boolean

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        b = True
    End Sub


    Private Sub txtName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtName.Validating
        Dim ico As New Icon(Application.StartupPath & _
        "\MSGBOX01.ico")
        ErrorProvider1.Icon = ico
        'If the Vaue is Number Then
        If IsNumeric(txtName.Text) Then
            ErrorProvider1.SetError(txtName, "Please Enter a string Value")
            e.Cancel = True
        Else
            ErrorProvider1.SetError(txtName, "")
        End If
    End Sub

    Private Sub txtpassword_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtpassword.Validating
        If Not IsNumeric(txtpassword.Text) Then
            Dim ico As New Icon(Application.StartupPath & _
            "\FACE04.ico")
            ErrorProvider1.Icon = ico
            ErrorProvider1.SetError(txtpassword, "Please Enter a Numeric Value")
            e.Cancel = b
        Else
            ErrorProvider1.SetError(txtpassword, "")


        End If
    End Sub


' This works perfectly
'//////////////////////////
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        b = False
        Me.Close()
    End Sub

'This I have no Idea
'it doesn't work ?
'//////////////////////////
    Private Sub btnInvoke_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInvoke.Click
        'TODO: I Don't Know why it does not work ?
        Dim myCancel As New System.ComponentModel.CancelEventArgs()
        myCancel.Cancel = False
        txtName_Validating(Nothing, myCancel)
        Me.Close()
    End Sub
 

Attachments

Last edited by a moderator:
Back
Top