Hello Roberto,
Here is a working sample for the problem. Please run and try to change the "Qty" column of the grid first.
Code: Select all
#include "minigui.ch"
Function Main
DEFINE WINDOW Win_1 ;
AT 0,0 ;
WIDTH 700 ;
HEIGHT 560 ;
TITLE 'Grid Edit Problem' ;
MAIN
DEFINE MAIN MENU
DEFINE POPUP 'Test'
MENUITEM 'Test' ACTION GridTest()
END POPUP
END MENU
END WINDOW
ACTIVATE WINDOW Win_1
Return
Function GridTest()
aRmnm := {"Natural Rubber", "PVC", "Sulphur"}
DEFINE WINDOW frmCompound ;
AT 0,0 ;
WIDTH 635 ;
HEIGHT 460 ;
TITLE 'Grid' ;
child ;
ON INIT FillGrid()
@ 10, 10 GRID grdCompoundRm ;
WIDTH 500 ;
HEIGHT 400 ;
HEADERS { 'Raw Material', 'Qty', '%' } ;
WIDTHS { 150, 75, 55 } ;
COLUMNCONTROLS { { 'COMBOBOX', aRmnm }, ;
{ 'TEXTBOX', 'NUMERIC', '9999.999' }, ;
{ 'TEXTBOX', 'NUMERIC', '999.99%' }} ;
CELLNAVIGATION ;
edit ;
justify { 0, 1, 1 } ;
on LOSTFOCUS calctot() ;
COLUMNWHEN { { || .t. }, { || .t. }, { || .f. } }
END WINDOW
CENTER WINDOW frmCompound
ACTIVATE WINDOW frmCompound
RETURN
Function FillGrid()
local i, aGrid := { {1, 10, 0.00}, {3, 5, 0.00}, {2, 5, 0.00}}
frmCompound.grdCompoundRm.DeleteAllItems()
for i = 1 to len( aGrid )
frmCompound.grdCompoundrm.additem( aGrid[ i ] )
next
return nil
static function CalcTot()
local a, i, j, aTemp := { }, mTotWt := 0.00
a := frmCompound.grdCompoundRm.value
i := a[1]
aTemp := frmCompound.grdCompoundRm.item( i )
if i < 1
return
endif
for j = 1 to frmCompound.grdCompoundRm.Itemcount
mTotWt += frmCompound.grdCompoundRm.cell( j, 2 )
next
aTemp[ 3 ] := round(aTemp[ 2 ] / iif(empty(mTotWt), 1, mTotWt)*100, 2)
frmCompound.grdCompoundRm.item( i ) := aTemp
return nil
Thank you very much.
With best regards.
Sudip