Textbox's validevent

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

All my textbox's validevent , need to pass its Text to another method for
testing.
my form got 10 textbox, I need to put the code me.fieldvalidation(Me.text)
for every TEXTBOX's validated event.

Any smart way that I only write a simple code, so. all the textbox can do
the same thing ??
thanks
 
write one sub that takes a String arg
in the validate event handler - add 'handles textbox2.validate,
textbox3.validate, etc to the "handles clause"
call the sub from the validate event - passing the sender.text property
 
Agnes,

Sometimes it is smart to search the newsgroups. This sample of my is as well
a little bit modified in the message from Dominique some threads bellow.

In that is the "cast of the sender" removed so I show you the original.

I hope this helps?

Cor

\\\
Dim last As String

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub

Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub

Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
last = DirectCast(sender, Control).Name
End Sub

Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).Text = last
End Sub
///
 
* "Agnes said:
All my textbox's validevent , need to pass its Text to another method for
testing.
my form got 10 textbox, I need to put the code me.fieldvalidation(Me.text)
for every TEXTBOX's validated event.

Any smart way that I only write a simple code, so. all the textbox can do
the same thing ??

Loop through the textboxes and use 'AddHandler' to add a common
'Validating' event handler. There you can call your valication routine:

\\\
Dim EventSource As TextBox = DirectCast(sender, TextBox)
Me.FieldValidation(EventSource.Text)
....
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top