Solved

Combining handlers...

Posted on 2012-03-15
3
188 Views
Last Modified: 2012-03-15
I have:

Private Sub txtMileage_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMileage.Validated
 
      Dim strVal = txtMileage.Text
.
.  
      txtMileage.Focus()
.
.
I want to turn this to handle 2 more text box entries, some thing like:

Private Sub txtMileage_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMileage.Validated, txtMiles.Validated, txtGas.Validated  '<--????
 
      Dim strVal = sender.Text    '<---????
.
.
     sender.Focus()   '<--- ?????

But I am not sure about the syntax of my code marked with '<--- ?????

Question: What is the correct syntax to accomplish this.

Also, what is the difference between Validated and Validating events and their use?

Thank you
0
Comment
Question by:Mike Eghtebas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 37726175
Generally speaking you can cast the sender object to a textbox:

    Private Sub txtMileage_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtMileage.Validated, txtMiles.Validated, txtGas.Validated  '<--????

        Dim txtbox As TextBox = DirectCast(sender, TextBox)
        Dim strVal As String = txtbox.Text

        txtbox.Focus()
    End Sub

Open in new window

You can also test if it's a specific textbox with code like this

If sender is txtGas Then

Open in new window


The main difference is that they occur at different points in the validation cycle.  See more about Validating, Validated etc. here:

Control.Validating Event
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 37726221
Thanks, I got it working. Do you have any comments on the second part:

Also, what is the difference between Validated and Validating events and their use?
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 37726223
oh sorry I didn't see your comment.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question