|
-
Jul 24th, 2013, 04:20 PM
#1
Thread Starter
Addicted Member
Key Return is detected in a secondary form
I have a primary form with a MSHierarchical Flexgrid control. when a press the enter key over the MSHierarchical Flexgrid control a secondary form is open.
The problem is that the enter key is detected by the secondary form and change the focus from the active control.
My question is how can i delete the keyboard buffer for the secondary form will not get the enter key ?
-
Jul 25th, 2013, 12:48 AM
#2
Re: Key Return is detected in a secondary form
Isn't it just a matter of clearing the key before loading the new Form?
Code:
Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCr) Then
KeyAscii = 0
Form2.Show
End If
End Sub
-
Jul 25th, 2013, 06:35 AM
#3
Re: Key Return is detected in a secondary form
And just for the heck of it, throw in a DoEvents, in the line prior to the Form2.show
Rob
PS If neither of those fixes you, knock up a tiny project that demonstrates your problem, and attach it for one of us to look at.
Last edited by Bobbles; Jul 25th, 2013 at 06:37 AM.
Reason: Adding a PS
-
Jul 25th, 2013, 08:20 AM
#4
Thread Starter
Addicted Member
Re: Key Return is detected in a secondary form
I'd try that you said but still the same. The solution that i found is to declare a public boolean variable called lLoadForm. Then before show the secondary form i set the value to True and at the secondary form, in the KeyUp control event to check the lLoadForm value.
Like this:
Private Sub TxtAmount_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn And IsNumeric(TxtAmount.Text) Then
If lLoadForm = True Then
lLoadForm = False
Else
CmdSave.SetFocus
End If
End If
End Sub
Thanks for the help to everyone
-
Jul 25th, 2013, 08:32 AM
#5
Re: Key Return is detected in a secondary form
Your first post was a bit light on detail.
It sounds like it was a control focus that was causing (or adding to) the problem.
My memory is a bit rusty (and old), so I don't fully recall the precise solution.
However if you add a textbox (or perhaps another control) to your form, and set it's Left property to -999 then it will not be visible.
Say we call it txtTakeFocus.
Set it's Tabstop to True and it's TabIndex to 0.
Now when your Form Loads, the focus can be handled (ignored).
I have resorted to that to solve more complex problems than the one you described.
Rob
Last edited by Bobbles; Jul 25th, 2013 at 08:46 AM.
Reason: Changed Index to TabIndex
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|