Solved

Combining handlers...

Posted on 2012-03-15
3
173 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
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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