0

In VS2010 I have Form1, 9 textboxes (TextBox1, 2, 3...) and 1 Button (Button1). In the first 8 textboxes a number is entered. Button1 is then clicked and the sum is returned to TextBox9. Everything works fine.

I am trying to get the sum in TextBox9 to update as a user enters a number and TABS through the eight textboxes starting in TextBox1. Here is what I have with no luck:

Private Sub Form1_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        Select Case e.KeyCode
            Case Keys.Tab
                Button1.PerformClick()

    End Select

Any help would be appreciated. Thanks.

2
Contributors
1
Reply
7
Views
1 Year
Discussion Span
Last Post by Reverend Jim
0

I suggest that instead of using a key type event you put your code in the textbox Leave event handler. That way any new text gets processed no matter how you leave the textbox. You can use the same handler for all 8 textboxes by

Private Sub TextBox_Leave(sender As System.Object, e As System.EventArgs)

    Button1.PerformClick()



End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    For i As Integer = 1 To 8
        Dim tbx As TextBox = Me.Controls("TextBox" & 1)
        AddHandler tbx.Leave, AddressOf TextBox_Leave
    Next

End Sub

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.