Solved

Combining handlers...

Posted on 2012-03-15
3
183 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

734 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