DeniseGoodheart
asked on
How to Use KeyDown Event with the Combo Box Control
Good Day:
I am creating a WinForms application using VS.NET 2005 and VB.NET 2005. I need to determine whether the user key pressed B or S in the combo box called cboType. I get an error message that reads: Cannot handle event keydown because they do not have the same signature. I tried the following and get the same error.
Private Sub cboType_KeyDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboType.KeyDown
If e.KeyValue=keys.B then
'Do Something
End sub
Private Sub cboType_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles cboType.KeyPress
If e.KeyValuee=keys.S then
'Do Something
End Sub
Any Suggestions?
Thank You,
Denise
I am creating a WinForms application using VS.NET 2005 and VB.NET 2005. I need to determine whether the user key pressed B or S in the combo box called cboType. I get an error message that reads: Cannot handle event keydown because they do not have the same signature. I tried the following and get the same error.
Private Sub cboType_KeyDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboType.KeyDown
If e.KeyValue=keys.B then
'Do Something
End sub
Private Sub cboType_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEv
If e.KeyValuee=keys.S then
'Do Something
End Sub
Any Suggestions?
Thank You,
Denise
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Sorry use the keyDown event
Private Sub cboType_KeyDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboType.KeyDown
If e.KeyCode=keys.B then
'Do Something
End sub
Private Sub cboType_KeyDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboType.KeyDown
If e.KeyCode=keys.B then
'Do Something
End sub
ASKER
Hello,
Thanks for all your suggestions. None of the suggestions work and I still get the same error.
And the msforms is not defined for the following:
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 66 Then
MsgBox "Key B pressed"
End If
Thanks for all your suggestions. None of the suggestions work and I still get the same error.
And the msforms is not defined for the following:
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 66 Then
MsgBox "Key B pressed"
End If
The keyDown was working for me, you did use the e.KeyCode not the KeyValue right?
I noticed above in your intial post your signature does not match this:
specifically the -> e As System.KeyEventArgs <-
specifically the -> e As System.KeyEventArgs <-
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
If e.KeyCode = Keys.B Then
'do something
End If
End Sub
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi!
Thanks for the points :)
Thanks for the points :)
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 66 Then
MsgBox "Key B pressed"
End If
End Sub