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: -
'This is the text box on top of the combo box in the detail section of the form.
-
' This event never gets triggered, so this code never runs.
-
Private Sub SCI_Name_TextBox_KeyDown(KeyCode As Integer, Shift As Integer)
-
-
' If user presses SHIFT+TAB on the first row....
-
If (KeyCode = vbKeyTab) And ((Shift And acShiftMask) > 0) Then
-
'only if we're on the first row...
-
If Me.CurrentRecord = 1 Then
-
' Disable the keystroke by setting it to 0
-
KeyCode = 0
-
'Set the focus to computer combo box
-
Me.computerComboBox.SetFocus
-
End If
-
-
End If
-
-
End Sub
-
-
'if the combo box is visible, then go ahead and set focus to it when you enter
-
'the text box
-
'I only included this because it's possibly related to the problem
-
'this appears to work correctly though....
-
Private Sub SCI_Name_TextBox_Enter()
-
If Me.SCINameComboBox.Visible Then
-
Me.SCINameComboBox.SetFocus
-
End If
-
End Sub
-
-
'This is the combo box underneath the text box. This event gets triggered
-
'when a key is pressed and works like a champ. (focus goes to the form
-
'header when you shift+tab from the first record, goes to the last control
-
'from the previous record otherwise)
-
Private Sub SCINameComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
-
-
' If user presses SHIFT+TAB on the first row....
-
If (KeyCode = vbKeyTab) And ((Shift And acShiftMask) > 0) Then
-
'only if we're on the first row...
-
If Me.CurrentRecord = 1 Then
-
If ((Shift And acShiftMask) > 0) Then
-
' Disable the keystroke by setting it to 0
-
KeyCode = 0
-
'Set the focus to computer combo box
-
Me.computerComboBox.SetFocus
-
End If
-
End If
-
-
Else
-
-
Select Case KeyCode
-
' If user presses TAB, ENTER
-
Case 13, 9
-
' Disable the keystroke by setting it to 0
-
KeyCode = 0
-
-
'Set the focus to the version drop down
-
Me.SCIDescriptionComboBox.SetFocus
-
Case Else
-
Debug.Print KeyCode, Shift
-
End Select
-
-
End If
-
End Sub
-
-
'combo box in the form header
-
'captures and ignores the error 2110 (couldn't set focus to the text box)
-
'because the set focus appears to work even though an error is thrown.
-
'not the best solution.. but this may be related to the other problem I'm seeing
-
Private Sub computerComboBox_KeyDown(KeyCode As Integer, Shift As Integer)
-
On Error GoTo Err_computerComboBox_KeyDown
-
Select Case KeyCode
-
' If user presses TAB, ENTER
-
Case 13, 9
-
If Not IsNull(Me.computerComboBox) Then
-
' Disable the keystroke by setting it to 0
-
KeyCode = 0
-
-
'Set the focus to the first control in the detail view
-
Me.SCI_Name_TextBox.SetFocus
-
End If
-
Case Else
-
Debug.Print KeyCode, Shift
-
End Select
-
Exit_computerComboBox_KeyDown:
-
Exit Sub
-
-
Err_computerComboBox_KeyDown:
-
If Not (Err.Number = 2110) Then
-
MsgBox Err.Description
-
End If
-
Resume Exit_computerComboBox_KeyDown
-
-
End Sub
-
Thanks in advance for any ideas!
Dana
1 5838
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:">
|
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?
|
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)...
|
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;
|
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
| |
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...
|
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}")
|
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...
|
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.
|
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...
|
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,...
| |
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |