Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I am entering data in a Textbox, and then using the tab to change focus to a second Textbox. Both textboxes are defined in a Handles statement on a Textbox_Validating event.

 

Private Sub TextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating, TextBox2.Validating

 

'ActiveControl.Name has TextBox2 when

' tabbing from Textbox1 to Textbox2

End Sub

 

I wanted to use a generic routine for simplicity. But in the validating event, I see that the ActiveControl.Name is the name of the second textbox, not the first textbox that I expected since it is the value in the first textbox that I am trying to validate.

 

Further testing shows that the Enter and GotFocus events maintain the ActiveControl.Name value of the first textbox. But

the Leave, Validating, Validated, and LostFocus events change

and have the value of the second textbox.

 

Is there some other generic way to tell in the Validating event which control is being validated?

 

Thanks,

Dave

Edited by jeaniedave
  • Administrators
Posted

The parameter 'sender' that is passed into the subroutine will be the control causing the Validating event to fire, you can cast this to the correct control type and use it within the sub.

 

Private Sub TextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating, TextBox2.Validating

dim t as TextBox
t = DirectCast(sender, TextBox)

't.Name should be the correct textbox name.
End Sub

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

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