Hi Rimintas,
Again a database object is going to be a good answer. It is automatically buffered.
However, it is difficult to do spreadsheet style editing with cell level validation and control. Also, how does one trigger the save? On a cell by cell basis or only when they are done with the entire record? And how is the implimented in the interface, i.e. how does the user know how it works?
For these reasons I rarely use in-browse editing. It is much easier to edit a record using a popup dialog when the record is double-clicked.
I am attaching a sample program that does cell by cell editing using a database object. Each cell's edit is saved by the user pressing the Return key (most users won't like this since it does not work like a standard spreadsheet). With some work you may be able to adapt it to your desires. I did not write the code, nor do I know who the author is.
James Bott
- Code: Select all Expand view RUN
/*
Purpose: XBrowse example with spreadsheet style editing
Note : Any alpha-numeric key triggers the edit, and up and down arrows exit the edit
Tested with FWH 8.08
Update: If you use lFastEdit, then exiting with the Return key doesn't work anymore.
*/
#include "FiveWin.ch"
#include "XBrowse.ch"
function Main()
local oWnd, oDbf, oBrw, oCol
USE Customer
DATABASE oDbf
DEFINE WINDOW oWnd
@ 0, 0 XBROWSE oBrw OF oWnd OBJECT oDbf
oBrw:lFastEdit:=.t. // any alpha-numeric key triggers the edit
oCol = oBrw:AddCol()
oCol:cHeader = "First"
oCol:bStrData = { || oDbf:First }
oBrw:aCols[ 1 ]:nEditType = EDIT_GET
oBrw:aCols[ 1 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:First := xVal, oDbf:Save(), oBrw:GoDown() ), (oDBF:First:= xVal, oDbf:Save()) ) }
oCol = oBrw:AddCol()
oCol:cHeader = "Last"
oCol:bStrData = { || oDbf:Last }
oBrw:aCols[ 2 ]:nEditType = EDIT_GET
oBrw:aCols[ 2 ]:bOnPostEdit = { | oCol, xVal, nKey | If( nKey == VK_RETURN, ( oDbf:Last := xVal, oDbf:Save(), oBrw:GoDown() ), (oDBF:First:= xVal, oDbf:Save()) ) }
oBrw:CreateFromCode()
oWnd:oClient = oBrw
ACTIVATE WINDOW oWnd
return nil