When the code below is executed if sometimes it performs a "TAB" sometimes does nothing and sometimes gets my PC hung so I have to do CTR-ALT-DEL & Cancel which moves the execution of the program to the next line ("End IF"). Any idea what is missing to make it work? No special settings for mtComboBx

Private Sub myComboBx_KeyPress(ByVal sender As Object, ByVal e As     
   System.Windows.Forms.KeyPressEventArgs) Handles batch_typeComboBx.KeyPress
        If e.KeyChar = Chr(13) Then
            System.Windows.Forms.SendKeys.Send(Chr(9))
        End If
    End Sub

Recommended Answers

All 4 Replies

Try this, you can send Enter as Tab and Enter + shift as Tab + Shift with it.

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
            SendKeys.Send("{TAB}")
        Else
            If e.KeyCode = Keys.Enter Then
                SendKeys.Send("{TAB}")
        End If
End If

I got the error 'KeyCode' is not a member of the System.Windows.Forms.KeyPressEventArgs.

Try this, you can send Enter as Tab and Enter + shift as Tab + Shift with it.

    If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
                SendKeys.Send("{TAB}")
            Else
                If e.KeyCode = Keys.Enter Then
                    SendKeys.Send("{TAB}")
            End If
    End If

Use KeyUp instead of KeyPress like this

Private Sub myComboBx_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myComboBx.KeyUp

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
SendKeys.Send("{TAB}")
Else
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If
End If

End Sub

Thank you for your efforts. Now it works both ways, with KeyCode and with KeyChar. It may have been setting Focus in 'Validating' event for the control that caused the malfunction.

Use KeyUp instead of KeyPress like this

Private Sub myComboBx_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myComboBx.KeyUp

If (e.Shift = True AndAlso e.KeyCode.Equals(Keys.Enter)) Then
SendKeys.Send("{TAB}")
Else
If e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
End If
End If

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.