Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Combining handlers...

Posted on 2012-03-15
3
Medium Priority
?
195 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 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