473,382 Members | 1,332 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,382 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 13385
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.