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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.