validating-event

Hello,

Can somebody tell me if it’s possible to get the name of the control (not the container !) that causes validation during the validating-event of a control that I’m leaving.

Thanks,

[1448 byte] By [georgemga] at [2007-12-16]
# 1

You can cast the sender argument in your event handler to Control and get the name:


Private Sub TextBox1_Validating(sender As Object, e As EventArgs)

Dim senderControl As Control = CType(sender, Control)

senderControl.Name ' Should be TextBox1

End Sub


DanielRieck at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Hi Daniel,

Thanks for your answer, but this is not what I’m looking for.

Consider I have a TextBox1 and a Textbox2 (both in different containers).

Textbox 1 has the focus. Now I click (or move with Tab) into Textbox2.

Can I get the name of Textbox2 in the validation-event of Textbox1 ?

Do you have an solution ?

Georg

georgemga at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
I don't think you can do that, because the Validating event of TextBox1 happens before the Enter event of TextBox2. But until TextBox2 is entered, you can't know which control was selected that made TextBox1 loose focus.
As long as you only Tab through them, you can use Form.GetNextControl, but with the mouse it could be anyone.
DanielRieck at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

About the name of the control, see in the good book:

http://msdn.microsoft.com/vbrun/staythepath/additionalresources/IntroTo2005/default.aspx

Free Book – Introducing Visual Basic 2005 for Developers

In Chapter 1 – Framework Class Librasry - Namespaces

The author says: Unless other information is provided for the compiler to resolve a class name, classes must be referred to using their fully qualified name. A fully qualified name is the class name preceded by its namespace. If the namespace is nested in another namespace, the full list of namespaces must be included in the fully qualified name. The fully qualified name for the class in the previous example is ChooseYourOwnNamespace.Namespace1.Class1.

If your TextBox are in the same Namespace, in the same Class ou not, but in different Forms, I think that applies to your case.

Sime?o (Pelotas - RS - Brasil)

Sime?o at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...