Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unbound Textbox in grid
Message
 
To
29/01/2003 15:59:15
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00746878
Message ID:
00746902
Views:
32
This message has been marked as the solution to the initial question of the thread.
Don, grab the appropriate property values and methods code from below. This seems to work.
My table2 table contained only one numeric wtkgs field. I did not do any work with decimals/rounding format inputmasks , etc. - you can figure this out.
**************************************************
*-- Form:         form1 (c:\z\form311.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   01/29/03 06:01:10 PM
*
DEFINE CLASS form1 AS form


	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 2, ;
		Height = 200, ;
		Left = 24, ;
		RecordSource = "table2", ;
		Top = 24, ;
		Width = 320, ;
		Name = "Grid1", ;
		Column1.ControlSource = "table2.wtkgs", ;
		Column1.Name = "Column1", ;
		Column2.Bound = .F., ;
		Column2.ControlSource = "", ;
		Column2.Sparse = .F., ;
		Column2.DynamicCurrentControl = "thisform.calcpounds()", ;
		Column2.Name = "Column2"


	ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
		Caption = "Kg", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column1.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = "Text1"


	ADD OBJECT form1.grid1.column2.header1 AS header WITH ;
		Caption = "Pound", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column2.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = "Text1"


	PROCEDURE calcpounds
		lparameter tn
		thisform.grid1.column2.Text1.Value = wtkgs*2.205
		return tn 
	ENDPROC


	PROCEDURE text1.Valid
		replace wtkgs with this.value/2.205
	ENDPROC


	PROCEDURE text1.GotFocus
		this.parent.parent.refresh()
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
>All,
>
>We use the the metric system to store our data. Weights are stored in kilograms.
>
>Some information from the US still only comes in the imperial system. Therefore I have been trying to provide a column in a grid showing the weight in pounds. (Yes we do data entry in grids - have for years). It will be next to column for weight in kilos.
>
>The source for the data is wtkgs * 2.205. In a form it is easy. I use a unbounded textbox and calculate the value (wtkgs * 2.205) in the Refresh method. If the user enters a new weight in pounds I catch the change in the valid method. I calculate the wt in kgs and enter it into the wtkgs field.
>
>(The weight in pounds is not stored in the table. This would seem to be trouble since it is the same information, just in different units. Someday they will not be the same and we will not know which is correct.)
>
>I tried the same in a textbox in a grid.
>
>First Try :
>procedure Init (for textbox)
>oColumn = this.Parent
>oColumn.ControlSource = "wtkgs"
>oColumn.Bound = .f.
>oColumn.Sparse = .t.
>this.ControlSource = ""
>this.cControlSource = "wtkgs"
>
>Procedure Refresh
>this.Value = eval(this.cControlSource) * 2.205
>
>procedure Valid
>replace (this.cControlSource) with this.Value / 2.205
>
>This showed the weight in kgs in both columns unless the weight in pounds column has the focus, then only the row that has focus shows the weight in pounds.
>
>Second Try :
>procedure Init (for textbox)
>oColumn = this.Parent
>oColumn.ControlSource = ""
>oColumn.Bound = .f.
>oColumn.Sparse = .f.
>this.ControlSource = ""
>this.cControlSource = "wtkgs"
>
>Refresh & Valid remain the same
>
>This showed blanks in the weight in pounds column.
>
>Same thing happened setting :
>
>oColumn.ControlSource = "wtkgs" and oColumn.Sparse = .f.
>
>I am now at a loss to continue. Can anyone help point me on the way.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform