473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trap Enter Key in ComboBox?

I'm trying to trap the Enter key in any of the key events
(keypress, keydown, keyup) of the Windows .Net combobox
control. Try as I might, I cannot get the event to
respond to an Enter key press; nor can I find anything
documenting this situation. Help is appreciated.

Here's my code. This pops up a messagebox for normal
alphanumeric keys, but does nothing at all when Enter is
pressed.

Private Sub cboLoan_KeyDown(ByVal sender As Object, ByVal
e As System.Windows.Forms.KeyEventArgs) Handles
cboLoan.KeyDown
If e.KeyCode = Keys.Return Then
MessageBox.Show("KeyDown: got it")
End If
End Sub

Private Sub cboLoan_KeyPress(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs)
Handles cboLoan.KeyPress
If e.KeyChar = ChrW(13) Then
MessageBox.Show("KeyPress: got it")
End If
End Sub

Private Sub cboLoan_KeyUp(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyEventArgs) Handles
cboLoan.KeyUp
If e.KeyCode = Keys.Return Then
MessageBox.Show("KeyUp: got it")
End If
End Sub
Jul 19 '05 #1
2 13388
Try use the override ProcessDialogKey of the form that has the combobox. In
this function return true if you handled the key, otherwise return
mybase.processdialogkey(...) and the program will continue as if the
override wasn't there.

Good luck,
Guillaume Hanique.
"Fred Sawtelle" <no**************@hotmail.com> wrote in message
news:05****************************@phx.gbl...
I'm trying to trap the Enter key in any of the key events
(keypress, keydown, keyup) of the Windows .Net combobox
control. Try as I might, I cannot get the event to
respond to an Enter key press; nor can I find anything
documenting this situation. Help is appreciated.

Here's my code. This pops up a messagebox for normal
alphanumeric keys, but does nothing at all when Enter is
pressed.

Private Sub cboLoan_KeyDown(ByVal sender As Object, ByVal
e As System.Windows.Forms.KeyEventArgs) Handles
cboLoan.KeyDown
If e.KeyCode = Keys.Return Then
MessageBox.Show("KeyDown: got it")
End If
End Sub

Private Sub cboLoan_KeyPress(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs)
Handles cboLoan.KeyPress
If e.KeyChar = ChrW(13) Then
MessageBox.Show("KeyPress: got it")
End If
End Sub

Private Sub cboLoan_KeyUp(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyEventArgs) Handles
cboLoan.KeyUp
If e.KeyCode = Keys.Return Then
MessageBox.Show("KeyUp: got it")
End If
End Sub

Jul 19 '05 #2
You're using the wrong ENUM value. try this:

If e.KeyCode = Keys.Enter Then

MsgBox("got it!")

End If
--
Regards,

Roy Osherove
http://www.iserializable.com
---------------------------------------------

"Fred Sawtelle" <no**************@hotmail.com> wrote in message
news:05****************************@phx.gbl...
I'm trying to trap the Enter key in any of the key events
(keypress, keydown, keyup) of the Windows .Net combobox
control. Try as I might, I cannot get the event to
respond to an Enter key press; nor can I find anything
documenting this situation. Help is appreciated.

Here's my code. This pops up a messagebox for normal
alphanumeric keys, but does nothing at all when Enter is
pressed.

Private Sub cboLoan_KeyDown(ByVal sender As Object, ByVal
e As System.Windows.Forms.KeyEventArgs) Handles
cboLoan.KeyDown
If e.KeyCode = Keys.Return Then
MessageBox.Show("KeyDown: got it")
End If
End Sub

Private Sub cboLoan_KeyPress(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs)
Handles cboLoan.KeyPress
If e.KeyChar = ChrW(13) Then
MessageBox.Show("KeyPress: got it")
End If
End Sub

Private Sub cboLoan_KeyUp(ByVal sender As Object, ByVal e
As System.Windows.Forms.KeyEventArgs) Handles
cboLoan.KeyUp
If e.KeyCode = Keys.Return Then
MessageBox.Show("KeyUp: got it")
End If
End Sub

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fred Sawtelle | last post by:
I'm trying to trap the Enter key in any of the key events (keypress, keydown, keyup) of the Windows .Net combobox control. Try as I might, I cannot get the event to respond to an Enter key press;...
3
by: RR | last post by:
What would the proper way be to enter a sale, then be able to enter 1 or more sales persons, their "costs" to the sale, and their commission on the sale? Then after its been entered, have all the...
8
by: ShyGuy | last post by:
Is it possible to use code to enter some text into a combo box and then have the cursor placed at the end of the text for more imput?
2
by: Rich | last post by:
Hello, I need to trap/detect when a textbox is entered via the tabkey. If the textbox is not empty when entered via the tabkey then set focus to next textbox. To enter that textbox would then...
8
by: =?Utf-8?B?RyBIdXN0aXM=?= | last post by:
This is the 2nd time posting so sorry for duplications. I am using VB.NT 2005 & a standard Combobox. I've been wracking my brain over this problem for a over a month & cannot seem to find a way to...
4
by: kveerendrareddy | last post by:
Hi friends, In my web page i have to create a combobox in HTML+JavaScript. The nature of that combobox should be such that it should allow the user to enter the data in the combobox...
1
by: Andrus | last post by:
I need to enter null value from combobox to business object property. My combobox datasource does not contain ValueMember with null value. So I tried to create combobox which stores null to bound...
1
by: sjarmy | last post by:
I am using javascript to make a dropdownlist act like a combobox and it is work well. The issue I'm having is when the user types in the combobox and finds the selection he wants, he has to use the...
2
by: EManning | last post by:
I posted a question on 5/5/08 asking how to trap an error caused by multiple users trying to access the same patient. Here's what I posted: "Using A2003. I've got an FE with a main form with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.