-
Apr 20th, 2004, 04:58 AM
#1
Thread Starter
Frenzied Member
Not Resolved -> KeyDown or KeyPress Not always working
I have a MSHFlexGrid, but the KeyPress or KeyDown methods don't always work.
E.G. You can see that the grid has focus. But when you press the Insert Key, on the keyboard, it doesn't always trigger the KeyDown Event, it does most of the time but not always. Same if the grid has focus and you press a letter, it doesn't always trigger the KeyPress Event.
Why is this?
Last edited by mel_flynn; Apr 22nd, 2004 at 04:55 AM.
Mel
-
Apr 20th, 2004, 06:25 AM
#2
Thread Starter
Frenzied Member
Can anyone shed any light on this matter? It's quite important. Why would pressing a key on the keyboard not trigger the KeyDown or KeyPress Events?
-
Apr 20th, 2004, 06:35 AM
#3
Hyperactive Member
Im not pretty sure, but when I used to work with the KeyPress event on forms, I would always adjust the KeyPreview property of the Form to true. Maybe that will help --- but Im not pretty sure.
-
Apr 20th, 2004, 06:37 AM
#4
Addicted Member
Just for the heck of it... try setting the KeyPreview of the form to TRUE. In the form's KeyDown event, test the VBKeyInsert and pass the code as required.
Never tie a rock to your ankle while randomly selecting stones to throw from high places.
-
Apr 20th, 2004, 06:39 AM
#5
Addicted Member
Frodo
Sorry... you beat me to the punch. Didn't mean to reiterate.
Never tie a rock to your ankle while randomly selecting stones to throw from high places.
-
Apr 20th, 2004, 06:45 AM
#6
Thread Starter
Frenzied Member
I tried setting the KeyPreview on the form to true, but still, sometimes, when I press a key when my grid has focus, it's not triggering the KeyDown or KeyPress Event of the Grid.
This is driving me mad
-
Apr 20th, 2004, 06:51 AM
#7
Addicted Member
Haven't worked much with FlexGrid... are you sure you have the latest upgrades and patches?
Never tie a rock to your ankle while randomly selecting stones to throw from high places.
-
Apr 20th, 2004, 06:55 AM
#8
Thread Starter
Frenzied Member
Well I'm running VB6 (SP5), I think that's the latest??
-
Apr 20th, 2004, 07:01 AM
#9
Addicted Member
Ok... I'll work with it and get back to you. In the mean time, maybe someone else will post an answer.
Never tie a rock to your ankle while randomly selecting stones to throw from high places.
-
Apr 20th, 2004, 08:13 AM
#10
Addicted Member
I'm not sure there is a KeyAscii equilalent to the Insert Key, therefore; Keypress will fail...
Use KeyDown and KeyUp instead... to prove the point... create a new project and install a FlexGrid named MSFlexGrid1. Add the following:
VB Code:
Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
'Will be received
If KeyCode = vbKeyInsert Then
MsgBox "I've got KeyDown focus"
End If
End Sub
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
'will not be received
If KeyAscii = vbKeyInsert Then
MsgBox "I've got KeyPress focus"
End If
End Sub
Never tie a rock to your ankle while randomly selecting stones to throw from high places.
-
Apr 20th, 2004, 08:17 AM
#11
Frenzied Member
SP6 is out
Originally posted by mel_flynn
Well I'm running VB6 (SP5), I think that's the latest??
-
Apr 20th, 2004, 10:21 AM
#12
Can you recreate the problem or does it happen randomly?
Is the flexgrid data bound?
Does the flexgrid really have the focus?
Try the KeyPreview property of the Form again. Put this code in the Form_KeyDown event.
Debug.print Me.ActiveControl.Name, vbkeycode
Then, when it seems the Insert key is not being recognized by the FlexGrid, this will display the name of the control that has the focus. At least you will know if it is a flex grid problem or caused elsewhere.
-
Apr 21st, 2004, 06:46 AM
#13
Thread Starter
Frenzied Member
I'm not sure there is a KeyAscii equilalent to the Insert Key, therefore; Keypress will fail...
I realise this, I am using the KeyDown to trap Non-alphanumeric keys like INSERT; ENTER; DELETE etc, and I am using the the KeyPress Event to trap all alphanumeric keys. I don't think that this is the problem.
Can you recreate the problem or does it happen randomly?
Is the flexgrid data bound?
Does the flexgrid really have the focus?
1. I can't intentionally recreate it, it's happening randomly, not sure what's triggering it to happen.
2. The MSHFlexgrid isn't databound, I'm populating it by adding the data to the grid with a loop.
3. Yes the grid has focus as when I arrow left, right, up or down it moves from cell to cell, but again doesn't trigger the KeyDown event.
-
Apr 21st, 2004, 07:00 AM
#14
Thread Starter
Frenzied Member
OK really weird. I'm stepping through the code now and it's not calling the KeyDown Event when I press INSERT; DELETE or RETURN, but it will call the KeyDown Event when I press any of the arrows, or the PageUp and Down Key or the Home and End Keys. It will call it when I press Alt but not when I press Ctrl. It will call it when I press F10 but won't for any other F- Key. It won't call it for ESC.
Why is this?????
-
Apr 22nd, 2004, 04:56 AM
#15
Thread Starter
Frenzied Member
-
Apr 22nd, 2004, 09:08 AM
#16
Hyperactive Member
yes... for the use of the INSERT and DELETE and HOME, etc ...
you need to trap the KeyCode ... I don't have at hand the list of keys that you only get to catch thru KeyDown
but I use the KeyDown in a ListView to trap INSERT (45) and DELETE (46) to add and to delete entries in it.
btw,
do a search for "keycode constants" inside MSDN ...and you'll get the list of them
"Who Dares Wins" - "Quien se Arriesga Gana"
Mail me at:
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
|