My problems were with the ON KEY function where I just could not get the right data to display and I have discovered this seems to be because I had inserted a MSGINFO() call within the ON KEY function (for testing). When I removed this, everything worked properly and the right data was
displayed.
I'm sure there is a simple explanation (surely not a bug?) for this and I am keen to learn more just in case I ever need to interrupt the function by adding something that pauses the function called by ON KEY rather than it running without interruption...
Hope this all makes sense!
Z
The program is almost 1000 lines, so I have extracted the sections that are of most interest.
Code: Select all
DEFINE GRID Grd_Emps
ROW 40
COL 40
WIDTH 270
HEIGHT 710
WIDTHS { 80, 155, 155, 155}
HEADERS {"Emp. No", "Surname", "Forename", "Dept."}
ALLOWEDIT .F. // False. Seperate button for this.
COLUMNCONTROLS Nil // { aCtrl_1 , aCtrl_2 , aCtrl_3 , aCtrl_4 , aCtrl_5 , aCtrl_6 } // Controls the GUI objects value - linked to above
SHOWHEADERS .T.
ROWSOURCE "Users" // Database file alias
COLUMNFIELDS { "USERNUMB", "SURNAME", "FORENAME", "DEPARTMT"}
ALLOWAPPEND .F. // False. Seperate button for this.
ALLOWDELETE .F. // False. NOT allowed with users!
ONCLICK Win_Grid_Click() // Works perfectly!
ONKEY Win_Grid_Key() // BIG PROBLEMS WITH RESULTS IF I USE MSGINFO() inside of Win_Grid_Key()
END GRID
// ************************************************************ //
FUNCTION Win_Grid_Key()
LOCAL lChange := .F.
LOCAL nKey := 0
nKey := HMG_GetLastVirtualKeyDown()
DO CASE
CASE nKey == VK_DOWN // Arrow Down
// THE FUNCTION BELOW HAS BEEN COMMENTED OUT AS IT CAUSED VERY ERRATIC RESULTS!
// IT APPEARS THAT THE INTERRUPTION TO PROCESSING RESULTS IN THE FUNCTION RETURNING
// THE OLD CELLROWFOCUSED VALUE RATHER THAT THE ONE IT SHOULD BE WHEN THE ARROW DOWN
// IS REMOVED. TAKING THIS FUNCTION OUT SOLVED THE PROBLEM!!!
//MsgInfo(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))
Users->( DBSEEK(CTON(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))) )
lChange := .T.
CASE nKey == VK_UP // Arrow Up
// AS ABOVE!
//MsgInfo(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))
Users->( DBSEEK(CTON(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))) )
lChange := .T.
CASE nKey == VK_NEXT // Page Down
Users->( DBGOBOTTOM() )
lChange := .T.
CASE nKey == VK_PRIOR // Page Up
Users->( DBGOTOP() )
lChange := .T.
OTHERWISE
lChange := .F.
ENDCASE
// The user has selected a different row in the grid. Move to the
// new record, then refresh the controls outside of the grid
// to show the new data
If lChange
Win_Admin_Refresh()
ENDIF
RETURN Nil