Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

Gary Says: To be a good programmer, you must be good at debugging
  • *Experts*
Posted

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 :).

  • *Experts*
Posted

Actually, what you need to do is create a CancelEventArgs, not a boolean, and pass that in.

 

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

txtName_Validating(Nothing, args)

Posted (edited)

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

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

errorprovider.zip

Edited by PlausiblyDamp
Gary Says: To be a good programmer, you must be good at debugging

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...