>Hello,
>
>I tried sending this earlier but it hasn't appeared, so here goes again.
>
>I'd like to update textboxes from values in a grid. I have a form method in the stgrid1.column1.text1 click event, which has this code.
>***click event
>thisform.setall("visible", .t.,"sttextbox")
>thisform.setall("visible", .t.,"stlabel")
>store ThisForm.Stgrid1.Column1.Text1.value to ThisForm.Sttxthipno.value
>store ThisForm.Stgrid1.Column2.Text1.value to ThisForm.Sttxtname.value
>store thisForm.Stgrid1.Column3.Text1.value to ThisForm.Sttxtacct.value
>store ThisForm.Stgrid1.Column4.Text1.value to ThisForm.Sttxtamtbid.value
>store ThisForm.Stgrid1.Column5.Text1.value to ThisForm.Sttxtamtpaid.value
>store ThisForm.Stgrid1.Column7.Text1.value to ThisForm.Sttxttype.value
>mamtdue = stntrans.amount - stntrans.amtpaid
>mbilldate = stntrans.billdate
>store mbilldate to ThisForm.Sttxtdatebill.value
>select stnbuyer
>seek trim(thisForm.Stgrid1.Column3.Text1.value)
>if fname <> " "
>mlname = trim(fname) + " " + trim(lname)
>else
>mlname = trim(lname)
>endif
>maddress = trim(city) + ', ' + trim(state) + ' ' + country
>store mlname to ThisForm.Sttxtlname.value
>store maddress to ThisForm.Sttxtaddress.value
>mldate = ThisForm.Sttxtmldate.value
>mlastbilldate = ThisForm.Sttxtmlastbilldate.value
>store ThisForm.Sttxtmlastbilldate.value to ThisForm.Sttxtlstbilldte.value
>store ThisForm.Sttxtmldate.value to ThisForm.Sttxtservicedate.value
>mcnt = mldate - mlastbilldate
>mtot = (mamtdue * .0005) * mcnt
>store mcnt to ThisForm.Sttxtlatecharge.value
>thisform.refresh
>***end of method
>
>When the form refreshes, the only textbox with the new values is the one which relates to the grid1.column1.text1.
>
>If I move the method to another grid textbox and click there it will update the textbox it relates to but not the others.
>
>Any ideas would be appreciated.
>
>Thanks,
>
>Jim Harvey
>jharvey@netrax.net
Jim,
You have hit a grid "behaviour" :) A quick fix is to replace those series of (thinking columns are rarely w/o controlsources) :
store ThisForm.Stgrid1.Column1.Text1.value to ThisForm.Sttxthipno.value
with :
store eval(ThisForm.Stgrid1.Column1.Text1.controlsource) to ThisForm.Sttxthipno.value
Better would be (you or someone else could change gridname, columnname or text1 name) :
ThisForm.Sttxthipno.value = myTable.myField
Also I noticed calculations and placing results of it in textboxes. In that case "programmaticchange" is a good place to put the code so you don't have to worry about duplicating code in more places. ie:
mamtdue = stntrans.amount - stntrans.amtpaid
If all are in textboxes, something like this in prog.change of textboxes of amount and amtpaid would do the job :
thisform.txtmAmtDue.Value = thisform.txtAmount.value - thisform.txtAmtPaid.value
(We are going away from original question but couldn't resist :)
if fname <> " "
mlname = trim(fname) + " " + trim(lname)
else
mlname = trim(lname)
endif
block could just be :
mlname = alltrim(trim(fname) + " " + lname)
You also have :
select stnbuyer
seek trim(thisForm.Stgrid1.Column3.Text1.value)
....
I would suggest :
if seek(trim(thisForm.Stgrid1.Column3.Text1.value), "stnbuyer",cStnTAGNAME)
....
endif
because rarely you could hit side effects of cahnging workareas while in grid (I don't have a clear list what they could be - quick ones that comes to mind are that since you're leaving current rec, rowbuffering might update, record level validation fire etc).
Better yet I would suggest a Select-SQL into array there.
Next, since textboxes do not have controlsources and behave like memvars you don't need thisform.refresh at the end (which in turn might fire unwanted side effects especially in parent-child situation).
Last, if this code is to be called from every click in all columns and is appropriate to have it w/o a click then the form.code could move to grid.AfterRowColchange and free you coding it into all textboxes (or subclassing textboxes just for this).
Cetin