Results 1 to 2 of 2

Thread: Event Firing Order

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Unhappy Event Firing Order

    I have been plagued with an issue that I cannot nail down. Here is the scenario:

    I have a TextBox on a form that is bound using a typed DataSet. This TextBox contains a date. When the data is bound to this TextBox, I setup Format and Parse handlers. I also setup a Validating handler for this field for additional checking purposes.

    Here is what is odd:
    - Form1 Binds the data, adds handlers for the Format and Parse routines and lastly adds the handler for Validating. If I put in a bogus date, say 99/99/9999, my Validating routine alerts the user as planned. Events fire - Validating -> Parse -> Format

    - Form2 does the exact same thing in the exact same order, but the Events fire - Parse -> Format -> Validating and the Validating routine gets the original database value passed in. (If I move the add handler code for Validating before the code that creates the handlers for Format and Parse, it works as intended.)

    It appears that on Form2, the Parse and Format routines are realizing there is a bogus date and reverting it back to the value in the database.

    Is there any way to control the order in which these events fire? This has been very painful as the events fire in a different order depending on what form they are on.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: Event Firing Order

    In debugging this situation, I moved the AddHandler statements for the Validating event into a separate SubRoutine. Now it works as intended on Form2.

    This works
    VB Code:
    1. Private Sub frmMaintCompany_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Call BindFormData()
    3.         Call SetupEventHandlers()
    4.         Call CreateDataset()
    5.     End Sub
    6.  
    7.     Private Sub SetupEventHandlers()
    8.         ' Add additional Handlers
    9.         AddHandler txtCurrentWorkDate.Validating, AddressOf AppRoutines.fDate_Validating
    10.         AddHandler txtCurrentWorkDate.TextChanged, AddressOf AppRoutines.f_TextChanged
    11.         AddHandler txtCurrentWorkDate.KeyPress, AddressOf AppRoutines.f_KeyPressNumeric
    12.     End Sub

    This does not
    VB Code:
    1. Private Sub frmMaintCompany_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Call BindFormData()
    3.         Call SetupEventHandlers()
    4.         Call CreateDataset()
    5.  
    6.         ' Add additional Handlers
    7.         AddHandler txtCurrentWorkDate.Validating, AddressOf AppRoutines.fDate_Validating
    8.         AddHandler txtCurrentWorkDate.TextChanged, AddressOf AppRoutines.f_TextChanged
    9.         AddHandler txtCurrentWorkDate.KeyPress, AddressOf AppRoutines.f_KeyPressNumeric
    10.     End Sub

    Any idea on what is going on here?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width