Solved

Combining handlers...

Posted on 2012-03-15
3
154 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
Comment Utility
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 33

Author Comment

by:Mike Eghtebas
Comment Utility
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 33

Author Comment

by:Mike Eghtebas
Comment Utility
oh sorry I didn't see your comment.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now