Avatar of DeniseGoodheart
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.KeyEventArgs) Handles cboType.KeyPress
If e.KeyValuee=keys.S then
'Do Something
End Sub

Any Suggestions?
Thank You,
Denise


.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
team2005

8/22/2022 - Mon
SOLUTION
jppinto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Hawkvalley1

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
orueda

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jppinto

Or use tis:

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
Hawkvalley1

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
DeniseGoodheart

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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Hawkvalley1

The keyDown was working for me, you did use the e.KeyCode not the KeyValue right?
Hawkvalley1

I noticed above in your intial post your signature does not match this:
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

Open in new window

SOLUTION
Alfredo Luis Torres Serrano

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
team2005

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
team2005

Hi!

Thanks for the points :)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.