|
-
Oct 23rd, 2003, 12:17 AM
#1
Thread Starter
Junior Member
ActiveControl.Name
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
Last edited by jeaniedave; Oct 23rd, 2003 at 12:24 AM.
-
Oct 23rd, 2003, 07:12 AM
#2
Fanatic Member
You should be able to use the sender object that you are passing into the validate method to determine what control fired the event.
-
Oct 23rd, 2003, 07:14 AM
#3
Fanatic Member
Forgot the sample - You should be able to do something like:
-
Oct 23rd, 2003, 10:03 AM
#4
Thread Starter
Junior Member
That's what I would have thought also. But sender does not have a .Name property.
-
Oct 23rd, 2003, 10:09 AM
#5
PowerPoster
It's because sender has been upcasted to object. Cast the object to either its underlying type or to Control and check the name property.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|