Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27382

VS 2010 Backspace to move back in Textbox

$
0
0
My code currently checks if text length is greater than "4" and automatically tabs to the next textbox. For added convenience to the user, I'd like it to also move to the previous textbox when the user hits backspace on an empty textbox. And finally, I'd like it so when a user presses Enter on a textbox, the field automatically saves. Currently, I have this code below:

Code:

Private Sub CheckEntry(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDate.TextChanged, txtStore.TextChanged

        Dim TB As TextBox = CType(sender, TextBox)
        If TB.Text.Length = TB.MaxLength Then

            If TB.SelectionStart = 4 Then
                Me.SelectNextControl(TB, True, True, False, False)
            End If
        End If

    End Sub

I know how to make it tab back from SelectNextControl, but I don't know how to make it do that automatically when backspace is pressed on an empty textbox? I tried adding this to my code, but got an error:

Code:

  '///////PROBLEM CODE HERE @"TB.KEYCODE =" ERROR: KEYCODE IS NOT A MEMBER OF 'SYSTEM.WINDOWS.FORMS.TEXTBOX'
        If TB.SelectionStart = 0 And
            TB.KeyCode = Keys.Back Then
            Me.SelectNextControl(TB, False, True, False, False)
        End If

I also tried changing the selection start to -1 and getting rid of the KeyCode bit, but of course that didn't work either. I'm sure the answer is pretty simple, but I'm just not finding it.

Viewing all articles
Browse latest Browse all 27382

Trending Articles