Hi There,
I am developing VB.NET 2003 window application having problem with the FORM KEYDOWN event.

Problem with cancelling the keydown event when the data check function return FALSE due to duplicate Debtor ID.
How to cancel the KeyDown

[B]Private Sub FrmDebtor_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

	If e.KeyCode = Keys.Tab Or e.KeyCode = keys.Enter Then
	        If Me.TabIndex = 1 Then
	 	If FCheckDuplicate = True Then
			e.KeyCode = Keys.Cancel
		End If
	       End If
	End If	
End Sub[/B]

Edited by LennieKuah: n/a

7 Years
Discussion Span
Last Post by LennieKuah

The Form's KeyDown event will only fire if the form has focus, if a textbox or button has focus then the KeyDown event will be raised on the control, not the form.
If you are checking the tabindex, i'm assuming you only want to process the KeyDown if the user is typing in a certain control.
If so, why not just handle the controls KeyDown event? You can use e.SuppressKeyPress = true to prevent the key from being passed to the underlying control.


Hi Ryshad
Thank you for the suggestion. I will try it out and get back to you.

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.