Trapping Keys with SIGRID

Started by JR Heathcote, April 21, 2006, 05:17:40 PM

Previous topic - Next topic

JR Heathcote

I'm trying to trap keys with SIGRID, generally with success, but it seems that two particular keys (DELETE and INSERT) cannot be trapped.  I'm using the following code:



Function SO_SIGRID_SI_GRID_MSG_GRID_KEYNAV (ControlIndex As Long, hWndForm As Dword, hWndControl As Dword, lpGridNavigation As Long) As Long

 Local iKeyVal As Long
 Local lStyle  As Long

 Local dStation As Double
 Local dOffset  As Double

 Local pGridNav As siGridNavigation Ptr
 Local sText As String
'------------------------------------------------------------------------

pGridNav = lpGridNavigation

 iKeyVal = @pGridNav.EditMsg.wParam
 glEDITROW = @pGridNav.Row
 glEDITCOL = @pGridNav.Col
 
 FF_TextBox_SetText(HWND_SO_WINMSG, "SO_SIGRID_SI_GRID_MSG_GRID_KEYNAV")
 
 SELECT CASE iKeyVal
   CASE %VK_ESCAPE
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_ESCAPE")

   CASE %VK_F1
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_F1")

CASE %VK_HELP
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_HELP")

   CASE %VK_INSERT
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_INSERT") 'Not recognized

   CASE %VK_DELETE
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_DELETE") 'Not recognized
   
   Case %VK_HOME
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_HOME")
   
   Case %VK_END
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_END")
   
   Case %VK_NEXT, %VK_PGDN
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_NEXT")
   
   Case %VK_PRIOR, %VK_PGUP
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_PRIOR")
   
   CASE %VK_UP
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_UP")

   CASE %VK_DOWN
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_DOWN")

   CASE %VK_LEFT
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_LEFT")

   CASE %VK_RIGHT
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_RIGHT")

CASE %VK_TAB
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_TAB")
       If glEDITCOL = 2 And glEDITROW + 1 > siGetRowCount(HWND_SO_SIGRID) Then
         Call siAddRow (HWND_SO_SIGRID, glEDITROW + 1, 1)  
       End If
       
   Case %VK_RETURN
     FF_TextBox_SetText(HWND_SO_KEYMSG, "VK_RETURN")

   Case Else
     sText = Hex$(iKeyVal)
     FF_TextBox_SetText(HWND_SO_KEYMSG, sText)

 END SELECT

End Function



This code should work, but does not for DELETE and INSERT.  As near as I can figure out the %VK_DELETE and %VK_INSERT key codes are never fired.  Does anybody else have experience with this phenomenon?  Is this a Firefly problem?

Elias Montoya

I tried to help, but i havent found a way yet... the message
SI_GRID_MSG_FUNCTION_KEY is listed twice, maybe the correct
notification is not listed because of that?

Elias Montoya

I did this to test if the message is ever sent:

FUNCTION FORM1_SIGRID1_CUSTOM ( _
                             ControlIndex  AS LONG,  _  ' index in Control Array
                             hWndForm      AS DWORD, _  ' handle of Form
                             hWndControl   AS DWORD, _  ' handle of Control
                             wMsg          AS LONG,  _  ' type of message
                             wParam        AS DWORD, _  ' first message parameter
                             lParam        AS LONG   _  ' second message parameter
                             ) AS LONG
                             
DIALOG SET TEXT HWNDFORM, TIME$

END FUNCTION


the parent dialog changes to display the time every time it receives any other notifications, but it doesnt change when pressing this 2 keys. Maybe
you will have to subclass it.

JR Heathcote

Elias, thanks for trying to solve this problem.  I would guess that SIGRID uses the INSERT and DELETE functionality as part of the individual cell editing and thus these particular keys are not trapable unless one subclasses the control as you say.  Maybe Chris Bristow can shed some light on this issue.  Thanks again.

Fred Harris

If one subclasses an SIGrid with SetWindowLong(), the address of which internal window procedure of the various component controls contained within the grid will one receive?  

Also, I'm not sure how the grid was actually constructed, whether an array
of text/edit boxes was used or not.  But if so, I'm wondering if it is possible
to obtain in some way the window handles of these text boxes.

What I'm in the process of doing right now is ripping an MSFlexGrid ActiveX control out of one of my projects and replacing it with the SIGrid.  I'm not sure how I want to handle data validation for data entered in the grid.  In the case of the MSFlexGrid, the default behavior of that grid upon
receiving a keypress was to do nothing, that is, the key code's character did not show up in the grid.  To echo it to the grid I'd do something like this:

grid.text = grid.text & Chr$(KeyAscii)

My theory on data validation has always been to not even allow invalid data to show up, so if I know at design time what the valid characters are for a column, I'll just not echo them to the cell.  So for a column that needs a date such as  11/15/1952, the only characters I'll echo using Select Case logic are the numeric digits and the '/' key.

In grids I built myself if I used text boxes or not I'd be able to filter in this sort of way with subclassing or otherwise.  How might one attack this issue with the SIGrid?  If one can not do validation at this low a level, then I suppose I'll just have to do it by retrieving whatever gets put in a cell against validation routines.

Fred Harris
Coal Township, Pennsylvania