Rao
Thank you for your sample .. I have two problems
1) eof can occur with the vertical scroll bar
2) eof can occur with the down arrow key
In your example .. both scenarios create a new row and your logic works .. however, in the repair business there may be 20 or 30 lines of detail on an invoice and the typical technician uses the vertical scroll bar to pan down thru all the rows ... and when the scroll bar hits EOF .. I was getting the run-away addnewrow.
Your code solves the run-away addnewrow problem.. but when the vertical scrollbar hits EOF .. it creates 1 new empty row .. which is much better than creating 30 new rows ..
What ultimately I wanted to do is be able to trap the down arrow key only at the Eof code-block and ignore any other inputs such as the vertical scroll bar. Inspired by your code I made two changes .. one to xBrowse.prg and the other to your code ..
Please consider this change to xBrowse METHOD KeyDown to allow the key value to be returned. This change allows me to test for bKeyDown and the down arrow key. I do know know if making this small code change would have any un-intended consequences ..
Please review my solution .. if there is another way to prevent the verticle scroll bar from tripping the eof code block, I am open to any ideas.
Thanks
Rick Lipkin
- Code: Select all Expand view
// xbrowse.prg
METHOD KeyDown
...
...
...
case nKey == VK_DOWN .and. !GetKeyState( VK_CONTROL )
if ::KeyNo == ::nLen .and. Empty( ::bPastEof ) .and. ::lRelyOnKeyNo
return 0
endif
::Select( 0 )
::GoDown()
::Select( 1 )
return ::Super:KeyDown( nKey, nFlags ) // proposed change rlipkin 02/09/2018
With the above changes I have modified your code as follows:
- Code: Select all Expand view
#include "fivewin.ch"
#include "adodef.ch"
static oCn
static cTable := "testappend"
//----------------------------------------------------------------------------//
function Main()
SetGetColorFocus()
FWNumFormat( "A", .t. )
oCn := FW_OpenAdoConnection( "xbrtest.mdb" )
if oCn == nil
? "Connect Fail"
return nil
endif
if .not. FW_AdoTableExists( cTable, oCn )
CreateTestTable()
endif
EditTable()
oCn:Close()
return nil
//----------------------------------------------------------------------------//
function CreateTestTable()
local aCols := { { "ITEM", "C", 10, 0 }, { "AMOUNT", "N", 12, 2 } }
local aData := { { "One", 1000 }, { "Two", 2000 }, { "Three", 3000 } }
local oRs
? "Creating Table"
FWAdoCreateTable( cTable, aCols, oCn )
// Add sample record
oRs := FW_OpenRecordSet( oCn, cTable )
AEval( aData, { |a| oRs:AddNew( { "item", "amount" }, a ) } )
oRs:Close()
return nil
//----------------------------------------------------------------------------//
function EditTable()
local oRs
local oDlg, oFont, oBrw
local lAppending := .f.
oRs := FW_OpenRecordSet( oCn, cTable, adLockBatchOptimistic )
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 400,500 PIXEL TRUEPIXEL FONT oFont
@ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oRs AUTOCOLS ;
COLSIZES "9999" ;
CELL LINES NOBORDER FASTEDIT
WITH OBJECT oBrw
:nStretchCol := STRETCHCOL_WIDEST
:nEditTypes := EDIT_GET
:bSaveData := { || oBrw:oRs:UpdateBatch(), lAppending := .f. }
* :bPastEof := { || If( lAppending, nil, ( oBrw:oRs:AddNew(), lAppending := .t., oBrw:Refresh() ) ) }
// code changes here to test for the down arrow key to trap eof -----------------------------------------------------
:bPastEof := { || oBrw:bKeyDown := { |nKey| if(nKey = VK_DOWN,;
(if(MsgYesNo("Add New Row?"),(oBrw:oRs:AddNew(),lAppending := .t.,oBrw:ReFresh()),)),)}}
//--------------------------------------------------------------------------------------------------------------------------
:bKeyDown := { |k| If( k == VK_DELETE, ( oBrw:Delete(), lAppending := .f., 0 ), nil ) }
:bClrStd := { || { CLR_BLACK, If( oBrw:oRs:Status == 1, 0xffff80, CLR_WHITE ) } }
//
//
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
oRs:CancelBatch()
oRs:Close()
return nil
//----------------------------------------------------------------------------//