-
I am using the MSFlexgrid and I am trying to capture the Keycode when the user hits the arrow keys on the keyboard but I notice that when the keys are used it does not fire the KeyPress or the KeyDown Events and I am not sure how to capture those keys. I also tried the LeaveCell() event also but I am not able to capture the event.
Here is a sample of my code:
for some reason it will not capture the keydown code.
Private Sub MSFlexGrid1_LeaveCell()
Dim KeyAscii As Integer
If Not MSFlexGrid1.Text > CStr(0) Then
MSFlexGrid1.Text = ""
End If
MSFlexGrid1 = Format$(MSFlexGrid1, "0.00") 'or whatever format
MSFlexGrid1.CellBackColor = &H80000005 'white
Select Case KeyAscii
Case vbKeyDown
With MSFlexGrid1
mlCellLeft = .CellLeft
mlCellTop = .CellTop
mlCellWidth = .CellWidth
mlCellHeight = .CellHeight
VScroll1.Visible = True
VScroll1.Left = mlCellLeft + 1480
VScroll1.Height = mlCellHeight
VScroll1.Top = mlCellTop + .Top + 20
End With
End Select
End Sub
-
Well you declare KeyAscii as an integer in the event but you never give it a value so in the Select Case statement KeyAscii will be zero.
Try this instead:
Code:
Private Declare Function GetAsyncKeyState _
Lib "user32" ( _
ByVal vKey As Long) As Integer
Private Sub MSFlexGrid1_LeaveCell()
If Not MSFlexGrid1.Text > CStr(0) Then
MSFlexGrid1.Text = ""
End If
MSFlexGrid1 = Format$(MSFlexGrid1, "0.00") 'or whatever format
MSFlexGrid1.CellBackColor = &H80000005 'white
If GetAsyncKeyState(vbKeyDown) Then
With MSFlexGrid1
mlCellLeft = .CellLeft
mlCellTop = .CellTop
mlCellWidth = .CellWidth
mlCellHeight = .CellHeight
VScroll1.Visible = True
VScroll1.Left = mlCellLeft + 1480
VScroll1.Height = mlCellHeight
VScroll1.Top = mlCellTop + .Top + 20
End With
End If
End Sub
Good luck!