2

I have a time entry form that contains a tabcontrol with tab pages for each day of the week. Within this control is a table layout panel that is holding together various textboxes/labels. For each day of the week, the inputs are named in a similar fashion:

txtMonWorkHours
txtMonPTOHours
txtMonOTHours
txtTuesWorkHours
txtTuesPTOHours
txtTuesOTHours
...

I am using ADO.net to load/save all these values from a database into their respective textboxes.

Photo of data entry form

What I am now trying to do now is provide a method to validate entry (which I have now finished on an individual event basis such as:

Private Sub txtMonIn_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMonIn.Leave
    ValidateTimeEntered(txtMonIn)
   End Sub

and

Private Sub txtMonIn_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMonIn.TextChanged
    TransitionTextPreValidate(txtMonIn)
End Sub

My question is: Is there a way to add the method I have created to all the textboxes I need without having to assign each method to each textbox event individually?

1
  • you can edit the Handles portion of the declaration ...Handles txtMonIn.TextChanged, txtTueIn.TextChanged ..... so all the TxtIn??? use the same proc, ditto with the others Commented Sep 25, 2013 at 17:47

1 Answer 1

2

Your events have the ability to handle multiple controls, that is why the "sender" object is passed, so you know who is calling the event. Try this, notice the end of the sub's declaration:

Private Sub txtWeekdayIn_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles  txtMonIn.Leave, txtTueIn.Leave, txtWedIn.Leave
    ValidateTimeEntered(sender)
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.