0
 Private Sub AccountType_KeyDOWN(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Return Then
            ProcessTabKey(True)
        End If
    End Sub
 Private Sub anytextbox_Enter(sender As Object, e As EventArgs) Handles Twitter.Enter, Email.Enter, PhoneNoOffice.Enter, PhoneNoHome.Enter, PhoneNoMobile.Enter, EName.Enter, AName.Enter, IDCode.Enter, ExpiryDate.Enter, BankAccount.Enter

        Dim txt As TextBox = DirectCast(sender, TextBox)
        stroldvalue = txt.Text

    End Sub

    Private Sub anytextbox_KeyDown(sender As Object, e As KeyEventArgs) Handles Twitter.KeyDown, Email.KeyDown, PhoneNoOffice.KeyDown, PhoneNoHome.KeyDown, PhoneNoMobile.KeyDown, EName.KeyDown, AName.KeyDown, IDCode.KeyDown, ExpiryDate.KeyDown, BankAccount.KeyDown
        Dim txt As TextBox = DirectCast(sender, TextBox)


        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab Then
            If txt.Text <> stroldvalue Then
                connectunauth()
                cmd = New SqlCommand("Insert into changes values(@id,@txtname,@oldval,@newval)", Variables.UnauthCon)
                cmd.Parameters.AddWithValue("@id", CustomerNo.Text)
                cmd.Parameters.AddWithValue("@txtname", txt.Name)
                cmd.Parameters.AddWithValue("@oldval", stroldvalue)
                cmd.Parameters.AddWithValue("@newval", txt.Text)
                cmd.ExecuteNonQuery()
                UnauthCon.Dispose()
                NOCHANGE = True
            End If
        End If
    End Sub

In the above code i face the following error: On entry into one textbox, the value is saved in stroldvalue. On pressing enter after changing in the above, the form_keydown event triggers first, which runs the anytextbox_enter event causing the stroldvalue to be overwritten by the next textbox value. and then the textbox keydown event triggers.

I tried keypress event for the form, but keypress event does not capture enter key press on combobox. What should i do so that the keydown of form triggers after textbox keydown event.

4

0 回答 0