Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid on Page of Pageframe goes Blank 3

Status
Not open for further replies.

white605

Technical User
Jan 20, 2003
394
US
I am pointing to a record in table1 (pre.dbf) and displaying data on the top of page5

I have grid1 on page5 of pageframe 1 on my form

grid1.recordsource is set to a table (thisone.dbf)
grid1.recordsourcetype is set to 0 - table
grid2.readonly=.t.
I put a command button above the grid with the following doed in the click event
Code:
SELECT begage,endage,years,annual,semi,qtr,monthly,mdraft,single, ;
		ROUND(single*pre.total_b,2) as single_amt, ;
		ROUND(annual*pre.total_b,2) as annual_amt, ;
		ROUND(semi*pre.total_b,2) as semi_amt, ;
		round(qtr*pre.total_b,2) as qtr_amt, ;
		ROUND(monthly*pre.total_b,2) as mon_amt, ;
		ROUND(mdraft*pre.total_b,2) as mfraft_amt ;
		from rates ;
	WHERE BETWEEN(pre.age,begage,endage) ;
	ORDER BY years ;
	INTO TABLE thisone.dbf

this.Parent.grid1.refresh
pre.age determines various amounts to pay insurance premiums

When I click the commandbutton the grid goes blank and will not refresh.
Will the grid do what im asking or is there a better approach?
 
Browzing thru the faq's i found magnon's code
Code:
thisform.grid1.recordsource="" && To avoid reconstruction
select * from table2 where table2.key=field2 INTO myCursor
thisform.grid1.recordsource="myCursor"
DODEFAULT() && To do the rest of the refresh
modified it to
Code:
this.parent.grid1.recordsource="" && To avoid reconstruction
SET SAFETY off
SELECT years, ;
		ROUND(single*pre.total_b,2) as single_amt, ;
		ROUND(annual*pre.total_b,2) as annual_amt, ;
		ROUND(semi*pre.total_b,2) as semi_amt, ;
		round(qtr*pre.total_b,2) as qtr_amt, ;
		ROUND(monthly*pre.total_b,2) as mon_amt, ;
		ROUND(mdraft*pre.total_b,2) as mfraft_amt, ;
		begage,endage,annual,semi,qtr,monthly,mdraft,single ;
		from rates ;
	WHERE BETWEEN(pre.age,begage,endage) ;
	ORDER BY years ;
	INTO TABLE thisone.dbf
THIS.PARENT.grid1.recordsource="thisone.dbf"
DODEFAULT() && To do the rest of the refresh
which seems to be getting closer to the goal, but, the grid is now resizing the columns if the button is clicked more than once
 
When the the cursor is being rebuilt, the columns are losing their control source because they are not bound.
Grid.column.resizeable = .f.

2 ways to do this.

Set the columns controlsource Again after rebuilding the cursor i.e. grid.column1.controlsource = <<fieldname>> after the above code. you dont need to set safety off, nor do you need the dodefault() unless its a user class.

The second (error free) way is create a method on the form, with a Parameter. Put your code, only to rebuild the cursor, in there and call it first from the form load. Hard code the grid's recordsource with the cursor and the recordsourcetype set to 1 - Alias, and the columns controlsource with the cursor fields. This way you have more control and do not have to guess which column holds what.

When the form opens, the grid will be populated.

Now In your commandutton Click you can put:
With This.Parent
.grid1.RecordSource=""
.<<rebuild Cursor method>>(pre.age)
.grid1.Refresh
Endwith

Again: this is to give you an idea on how to do it, you will have to fine tune
 
Marcia - Thanks for pointing me to a good article
Imaginecorp - The following method on my form works
Code:
*method selrate *select current rates based on pre_age from table rates.dbf

*DETERMINE WORK AREA SELECTED
	LOCAL lnselect
	lnselect=SELECT()

*select new data into temporary file

SELECT begage,endage,years,annual,semi,qtr,monthly,mdraft,single, ;
		ROUND(pre.total_b/single,2) as single_amt, ;
		ROUND(annual*pre.total_b,2) as annual_amt, ;
		ROUND(semi*pre.total_b,2) as semi_amt, ;
		round(qtr*pre.total_b,2) as qtr_amt, ;
		ROUND(monthly*pre.total_b,2) as mon_amt, ;
		ROUND(mdraft*pre.total_b,2) as mfraft_amt ;
		from rates ;
	WHERE BETWEEN(pre.age,begage,endage) ;
	ORDER BY years ;
	INTO cursor thistemp readwrite
	


SET SAFETY off	
*clean out currernt rates
	SELECT thisone
	ZAP IN thisone


*append data into current file
SELECT thisone
APPEND FROM DBF("thistemp")

*set work area back
SELECT(lnselect)

*refresh grid
thisform.pageframe1.page5.grid1.Refresh
 
Thank you. Undeserved though...

Without knowing the situation, the above code will be a problem in a multiuser environment as thisone.dbf will have to be opened exclusive.

Here is another way: (It will not resize the columns)

Code:
I am assuming pre.age,begage,endage are dates

***Grid INIT()
Lparameters pStartDate,pEndDate
Select pre
cString = Iif(Vartype(pStartDate) = "D" And Vartype(pEndDate) = "D",;
	" Where BETWEEN(pre.age,begage,endage) ","")
This.RecordSource = ""
Select begage,endage,years,annual,semi,qtr,monthly,mdraft,Single, ;
	ROUND(Single*pre.total_b,2) As single_amt, ;
	ROUND(annual*pre.total_b,2) As annual_amt, ;
	ROUND(semi*pre.total_b,2) As semi_amt, ;
	round(qtr*pre.total_b,2) As qtr_amt, ;
	ROUND(monthly*pre.total_b,2) As mon_amt, ;
	ROUND(mdraft*pre.total_b,2) As mfraft_amt ;
	from rates &cString ;
	ORDER By years ;
	INTO Cursor thisone
This.RecordSource = "thisone"
This.RecordSourceType = 1
This.Refresh

****Command button CLICK()
thisform.grid1.init(DATE(2006,1,1),DATE(2006,12,31))

You could put 2 textboxes to capture the dates and in their valid() you could call the Grid's init(). The Where will not fire unless Both parameters have a date in them.

I have obviously not tested the above code, but with my tables it works.
Again: this is to give you an idea on how it can be done, you will have to fine tune it.
 
Imagecorp - I ran into the open exclusive issue so in the init of the form i put the code to build a cursor readwrite instead of storing "thisone" in a table, and that solved the problem you refer to.
thanks
wjwjr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top