-
Hi! My program cannot detect when user press the navigation keys (for e.g. left arrow, right arrow, etc.) under KeyPress or KeyUp or KeyDown events of msflexgrid.
So I believe I need to used some Win API in order to detect all the navigation keys which I totally does not know how to do it.
Can anyone help me in this?
Thank you in advanced!
-
Try using this code. It works for me for backspace, left arrow, right arrow, up arrow, down arrow, enter moves to right. It wraps to next row at end of row...
To test, create new form, drop MSHFlexgrid control onto it, and paste this code in...
*********************************
' set up a 5 x 5 grid...
Private Sub Form_Load()
MSHFlexGrid1.Cols = 5
MSHFlexGrid1.Rows = 5
End Sub
Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
'check for carriage return - move to next cell...
If Chr(KeyAscii) = Chr(13) Then
If MSHFlexGrid1.Col >= MSHFlexGrid1.Cols - 1 Then
MSHFlexGrid1.Col = 1
If MSHFlexGrid1.Row >= MSHFlexGrid1.Rows - 1 Then
MSHFlexGrid1.Row = 1
Exit Sub
Else
MSHFlexGrid1.Row = MSHFlexGrid1.Row + 1
Exit Sub
End If
Else
MSHFlexGrid1.Col = MSHFlexGrid1.Col + 1
Exit Sub
End If
End If
' handle backspace
If Chr(KeyAscii) = Chr(8) Then
MSHFlexGrid1.Text = Mid(MSHFlexGrid1.Text, 1, Len(MSHFlexGrid1.Text) - 1)
Exit Sub
End If
'other key pressed... append to existing text
MSHFlexGrid1.Text = MSHFlexGrid1.Text & Chr(KeyAscii)
End Sub
******************************
As I said, this should work.