473,651 Members | 2,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

KeyDown event doesn't occur for Text Box

12 New Member
I have a form with several combo boxes in the header used to determine the records that will be displayed on the form. When I tab or enter from the last combo box in the header, I want the focus to move to the first control on the form. When I Shift+tab from the first control on the form, I want the focus to move to the last control in the header. The form is a continuous form.

The first control on the form is either a text box or a combo box, depending on whether you are entering a new record (the combo box is visible only when entering a new record). The problem is that the KeyDown event of the Text Box never occurs when I press a key and the TextBox appears to have focus.

Other relevant information: The SCI_Name_TextBo x and computerComboBo x are tab stops, but SCINameComboBox is not. All three are Enabled and Not Locked.

Any ideas as to why this event is not getting triggered? Is there an alternative way to capture the Shift+Tab from the text box?

Following is my relevant code:

Expand|Select|Wrap|Line Numbers
  1. 'This is the text box on top of the combo box in the detail section of the form.
  2. ' This event never gets triggered, so this code never runs.
  3. Private Sub SCI_Name_TextBox_KeyDown(KeyCode As Integer, Shift As Integer)
  4.  
  5.  ' If user presses SHIFT+TAB on the first row....
  6.    If (KeyCode = vbKeyTab) And ((Shift And acShiftMask) > 0) Then
  7.             'only if we're on the first row...
  8.             If Me.CurrentRecord = 1 Then
  9.                 ' Disable the keystroke by setting it to 0
  10.                 KeyCode = 0
  11.                 'Set the focus to computer combo box
  12.                 Me.computerComboBox.SetFocus
  13.             End If
  14.  
  15.    End If
  16.  
  17. End Sub
  18.  
  19. 'if the combo box is visible, then go ahead and set focus to it when you enter
  20. 'the text box
  21. 'I only included this because it's possibly related to the problem
  22. 'this appears to work correctly though....
  23. Private Sub SCI_Name_TextBox_Enter()
  24.     If Me.SCINameComboBox.Visible Then
  25.         Me.SCINameComboBox.SetFocus
  26.     End If
  27. End Sub
  28.  
  29. 'This is the combo box underneath the text box.  This event gets triggered
  30. 'when a key is pressed and works like a champ.  (focus goes to the form
  31. 'header when you shift+tab from the first record, goes to the last control
  32. 'from the previous record otherwise)
  33. Private Sub SCINameComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
  34.  
  35.  ' If user presses SHIFT+TAB on the first row....
  36.    If (KeyCode = vbKeyTab) And ((Shift And acShiftMask) > 0) Then
  37.             'only if we're on the first row...
  38.             If Me.CurrentRecord = 1 Then
  39.                 If ((Shift And acShiftMask) > 0) Then
  40.                     ' Disable the keystroke by setting it to 0
  41.                     KeyCode = 0
  42.                     'Set the focus to computer combo box
  43.                     Me.computerComboBox.SetFocus
  44.                 End If
  45.             End If
  46.  
  47.     Else
  48.  
  49.         Select Case KeyCode
  50.             ' If user presses TAB, ENTER
  51.             Case 13, 9
  52.                 ' Disable the keystroke by setting it to 0
  53.                 KeyCode = 0
  54.  
  55.                 'Set the focus to the version drop down
  56.                 Me.SCIDescriptionComboBox.SetFocus
  57.             Case Else
  58.                 Debug.Print KeyCode, Shift
  59.         End Select
  60.  
  61.     End If
  62. End Sub
  63.  
  64. 'combo box in the form header
  65. 'captures and ignores the error 2110 (couldn't set focus to the text box)
  66. 'because the set focus appears to work even though an error is thrown. 
  67. 'not the best solution.. but this may be related to the other problem I'm seeing
  68. Private Sub computerComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
  69. On Error GoTo Err_computerComboBox_KeyDown
  70.     Select Case KeyCode
  71.         ' If user presses TAB, ENTER
  72.         Case 13, 9
  73.             If Not IsNull(Me.computerComboBox) Then
  74.                 ' Disable the keystroke by setting it to 0
  75.                 KeyCode = 0
  76.  
  77.                 'Set the focus to the first control in the detail view
  78.                 Me.SCI_Name_TextBox.SetFocus
  79.             End If
  80.         Case Else
  81.             Debug.Print KeyCode, Shift
  82.     End Select
  83. Exit_computerComboBox_KeyDown:
  84.     Exit Sub
  85.  
  86. Err_computerComboBox_KeyDown:
  87.     If Not (Err.Number = 2110) Then
  88.         MsgBox Err.Description
  89.     End If
  90.     Resume Exit_computerComboBox_KeyDown
  91.  
  92. End Sub
  93.  
Thanks in advance for any ideas!

Dana
Mar 14 '07 #1
1 5838
dana1
12 New Member
Sheepishly... I must admit that only moments after posting, I thought of one more thing to try. The event procedure, for whatever reason, didn't get hooked up properly to the text box. So, I went into my text box properties and set the onKeyDown property to [Event Procedure] and everything is great.

Sorry!

Although if anyone has any ideas about that 2110 error.. feel free to respond :-)

Dana
Mar 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

34
4895
by: Andrew DeFaria | last post by:
I thought this would be fairly straight forward but apparently it's not. Given the following html file: <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <title>Test</title> </head> <body> <form method="post" action="javascript:">
4
34533
by: Mike M | last post by:
I am trying to detect the keydown of the arrow keys in a custom control that I am writing. As far as I can tell, pressing the arrow keys does not fire the KeyDown event at all. It behaves just like the tab key, passing focus to the next control in the tab order. The only events that fire are in the lost focus sequence (leave, validating, validated, etc.) Any ideas?
2
7018
by: Peter | last post by:
Hello Thanks for reviewing my question. I am trying to consume the Keydown event of the Cntrl-shift-E in a textbox and have noticed that when I press key this combination a beep is made even though the event works correctly? How can I get rid of this beep? I thought that setting the e.Handled to true would do it but no luck private void txtbxEmail_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e if ( (e.KeyCode == Keys.E)...
2
12209
by: orekinbck | last post by:
Hi There In C# windows app, .NET 2003 I have a text box with the following event handler: private void textBox3_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.A) e.Handled = true;
2
4092
by: ZS | last post by:
Hi, On a form , I'm trying to trap when a shift key is pressed. Can someone explain how the KeyUp,KeyDown and Key Press event works for Forms. Thanks -ZS
2
1706
by: Rasika WIJAYARATNE | last post by:
I have a form with a KeyDown event handler method attached to it. It has three text boxes and two buttons (buttons are attached to event handler). However when I debug, the form opens with the first text box focussed, and when I press enter the Win XP 'Default Beep' sound plays but does not fire the event handler (doesn't hit the break point inside it). The event handler is definitely wired up to the form control, does anyone know why this...
4
8622
by: Anne | last post by:
hie again, i have 3 textbox and i would like the user to go to the next textbox by pressing the 'ENTER' key. i have tried using this: Private Sub txtRequestor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtRequestor.KeyDown If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
3
5246
by: MLM450 | last post by:
I have a control that handles the KeyDown event but it does not seem to execute when a combination of keys is pressed - like CTRL+Z. If I press CTRL, it executes. If I press Z, it executes. But the handler does not see the combination. Now this control is contained within another control which is contained within another. The top most control does see the CTRL+Z. I can easily pass down the key info, but why does the nested control see...
5
3020
by: ApexData | last post by:
This follows a previous post, when I was trying to capture a key pressed during the immediate opening of a form (ie in the first 3-secs before processing any of the code that followed it. It was mentioned that the KeyDown event fires the instant a key is pressed down. So, if you place the following code in a form, you'll see my concern.
0
8357
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7298
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4285
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.