I found some problem using grid and refreshing it after appending records in tables. I am creating a small sample from my project to demonstrate this. When "Calculate" button is clicked, grid shows an extra record.
Code: Select all
#include <minigui.ch>
static aMonth := {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
Function main()
local adbf := {}
if select("tempsalreg") > 0
select tempsalreg
use
endif
aadd(adbf, {"Empnm", "C", 40, 0})
aadd(adbf, {"Workdays", "N", 2, 0})
aadd(adbf, {"Basic", "N", 10, 2})
aadd(adbf, {"DA", "N", 10, 2})
aadd(adbf, {"FA", "N", 10, 2})
//DBCREATE("tempsalreg", adbf, "SQLMIX", .T., "TEMPSALREG")
hb_dbcreatetemp("tempsalreg", adbf)
DEFINE WINDOW frmSalreg ;
WIDTH 700 ;
HEIGHT 550 ;
TITLE "Salary Register" ;
main
DEFINE LABEL lblYear
ROW 10
COL 20
WIDTH 31
HEIGHT 20
VALUE "Year:"
END LABEL
DEFINE SPINNER spnYear
ROW 10
COL 60
WIDTH 70
HEIGHT 24
RANGEMIN 1
RANGEMAX 2050
END SPINNER
DEFINE LABEL lblMonth
ROW 10
COL 220
WIDTH 45
HEIGHT 21
VALUE "Month:"
END LABEL
DEFINE COMBOBOX cboMonth
ROW 10
COL 270
WIDTH 100
HEIGHT 100
ITEMS aMonth
END COMBOBOX
DEFINE BUTTON cmdCalc
ROW 10
COL 470
WIDTH 100
HEIGHT 28
ACTION SalRegCalc()
CAPTION "&Calculate"
END BUTTON
DEFINE GRID GRID_1
ROW 50
COL 20
WIDTH 610
HEIGHT 380
HEADERS {"Employee", "Wk Days", "Basic", "DA", "FA"}
WIDTHS {200, 100, 100, 100, 100}
ROWSOURCE "TEMPSALREG"
COLUMNFIELDS {"EMPNM", "WORKDAYS", "BASIC", "DA", "FA"}
JUSTIFY {0, 1, 1, 1, 1}
COLUMNCONTROLS {{"TEXTBOX", "CHARACTER"}, {"TEXTBOX", "NUMERIC", "999"}, {"TEXTBOX", "NUMERIC", "99999999.99"}, {"TEXTBOX", "NUMERIC", "99999999.99"}, {"TEXTBOX", "NUMERIC", "99999999.99"}}
ALLOWEDIT .T.
END GRID
END WINDOW
frmSalreg.spnYear.value := year(date())
frmSalreg.cboMonth.value := month(date())
frmSalreg.Center
frmSalreg.Activate
if select("tempsalreg") > 0
select tempsalreg
use
endif
Return Nil
static function SalRegCalc()
local table := {}, i
SELECT TEMPSALREG
zap
for i := 1 to 10
aadd(table, {"Employee "+ltrim(str(i))})
next
//table := sql(mdb, "select empnm from emp order by slno")
for i = 1 to len(table)
append blank
replace empnm with table[i, 1]
next
FRMSALREG.GRID_1.REFRESH
return nil
Thanks in advance.
With best regards.