Raising an Event or . . . ?

Behrooz

Member
Joined
Feb 8, 2007
Messages
15
Programming Experience
5-10
Hello Every1

In VB.NET 2005

I have a command button on my form and its name is cmdDelete which I have some code to deleting records from database in the Click Event of cmdDelete.

I need to pressing Delete key on my keyboard and Raising the Click Event of cmdDelete.

Am I right to think about raising Event in this Task, If Yes how can I do that?

I think that its not a good idea to put the deleting records Code in a procedure and then calling that Procedur. Do u thing so?
 
Put this method in your code, you can handle other keystrokes with it too without having the focus be on a specific control

VB.NET:
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
 
 If keyData = Keys.Delete Then
    cmdDelete.PerformClick()
    Return True
 Else
    Return MyBase.ProcessCmdKey(msg, keyData) 'lets the form process further info 
 End If
 
End Function
 
Back
Top