Please start with this small sample as it is.
We used CUSTOMER.DBF in fwh\samples folder.
Code: Select all
function testxbr()
local oDlg, oFont, oBrw
USE C:\\FWH\\SAMPLES\\CUSTOMER NEW ALIAS CUST SHARED
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 700,400 PIXEL FONT oFont
@ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
DATASOURCE "CUST" ;
COLUMNS "First", "City", "Age", "Salary" ;
CELL LINES NOBORDER ;
FASTEDIT // FASTEDI enables edit on pressing any key
WITH OBJECT oBrw
:nEditTypes := EDIT_GET // We enable editing of all cells
//
:CreateFromCode() // Tells xbrowse we finished our coding
END
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
CLOSE CUST
return nil
Please use COLUMNS clause to specify the field names to display and edit. This enables XBrowse to internally get ready for edit, save and display the field contents. Important: Please do not use FIELDS clause.
By default, xbrowse does not allow the user to edit. We need to set the column object's DATA nEditType to EDIT_GET, etc. to enable edit. oBrw:nEditTypes := EDIT_GET is a short cut for assigining each oCol:nEditType := EDIT_GET.
When FASTEDIT is used, pressing any key invokes inline edit. If not, the user can start edit first by pressing ENTER key.
The entire process of editing the cell, locking/unlocking of the table, saving data and refreshing the browse is all automatic.
After testing this sample, you may then extend this sample to your DBFs and specifying your columns.
WHEN:
For each column, we can also specify a when condition and valid check:
oBrw:aCols[ 4 ]:bEditWhen := { || oBrw:aCols[ 3 ]:Value > 0 }
This is same as:
oBrw:Salary:bEditWhen := { || oBrw:Age:Value > 0 }
VALID:
oBrw:Age:bEditValid := { |oGet| oGet:Value() > 0 }
Note: bEditWhen and bEditValid should not contain any Screen I/O.