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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid Problem

Status
Not open for further replies.

FoxKid

MIS
Jun 8, 2003
92
0
0
IN
I am having a grid on a form where I am getting data through sql and I have written recordsource as :

SELECT constructi,width,SPACE(12) as code,SPACE(50) as fabricname,sum(order) as order,sum(issqty) as issqty,000000.000 as quantity FROM xpono WHERE ok=.t. into CURSOR xorder order by constructi,width group by constructi,width readwrite

Here in grid for column 7&8 I have assigned its width as 75.
But when this query run and data comes in the grid then these columns collapse and only 0 is seen in it. Why it is doing so. These column get resized to the width of the value of this field
please help


Thanks
 
FoxKid

Take a look at faq184-1813 "How to avoid grid reconstruction".


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,
Its not working.

Please help

Thanks
 
FoxKid

Its not working.

As the suggestion in the faq is a well known work around to the problem you describe, reponding "Its not working." is not really a very detailed response. When you set your record source to '' (no space) and do your sql and reset it to your cursor what do you get?



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,
In the refresh property of grid1 I have written :

this.recordsource=""
SELECT constructi,width,SPACE(12) as code,SPACE(50) as fabricname,sum(order) as order,sum(issqty) as issqty,000000.000 as quantity FROM xpono WHERE ok=.t. into CURSOR xorder order by constructi,width group by constructi,width readwrite
this.parent.parent.page2.grid1.recordsource="xorder"
DODEFAULT()

In grid1.recordsourcetype I have written 1-Alias.

But again when I run the form the last 2 columns i.e. column6 & 7 get collapsed. It doesn't show any error.

Thanks
 
HI,
In my opinion
----------------------------------------------
thisform.grdDetails.RecordSource="xorder"
thisform.grdDetails.RecordSourceType = 1
thisform.grdDetails.column1.ControlSource='xorder.<desired_field>'
thisform.grdDetails.column2.ControlSource='xorder.<desired_field>'
thisform.grdDetails.column3.ControlSource='xorder.<desired_field>'
thisform.grdDetails.Refresh
thisform.grdDetails.SetFocus

------------
i have done this and it is working. here u can mention the controlsource property of all the columns. 1 thing will help u more, which is, add a Method in form. and name it
like &quot;GrdRefresh&quot; then any time u need to construct the grid, u can use that method of the form.
 
FoxDevil,
I have tried the way you have suggested, but again the problem resists as it was earlier.

Please help

Thanks
 
FoxKid

SELECT constructi,width,SPACE(12) as code,SPACE(50) as fabricname,sum(order) as order,sum(issqty) as issqty,000000.000 as quantity FROM xpono WHERE ok=.t. into CURSOR xorder order by constructi,width group by constructi,width readwrite

First, you say &quot;Here in grid for column 7&8 I have assigned its width as 75.&quot;, but yet your sql only contains 7 fields?



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Sorry mike it was my typing error. Actually it is 6 & 7th column.
 
FoxKid

Sorry I cannot duplicate your problem. Here is an example by code, copy it in a program and run it. If you click on the reset grid button, it recreates a new cursor and resets the grid, but the grid does not loose its original state.:
Code:
Create Cursor myCursor (Name c(20),address c(20))
Insert Into myCursor (Name, address) Values (&quot;Mike&quot;,&quot;123&quot;)
Insert Into myCursor (Name, address) Values (&quot;Paul&quot;,&quot;321&quot;)
Insert Into myCursor (Name, address) Values (&quot;John&quot;,&quot;345&quot;)
Insert Into myCursor (Name, address) Values (&quot;Ringo&quot;,&quot;567&quot;)
Insert Into myCursor (Name, address) Values (&quot;Georges&quot;,&quot;987&quot;)
Go Top
Select *,00000000.00 As Number From myCursor Into Cursor myCursor2
Public oForm
oForm = Createobject(&quot;form&quot;)
oForm.Width = 450
oForm.AddObject(&quot;grid1&quot;,&quot;grid&quot;)
oForm.AddObject(&quot;command1&quot;,&quot;command1&quot;)
oForm.Grid1.Width =420
oForm.Grid1.Visible = .T.
oForm.Show()
Define Class command1 As CommandButton
	Visible = .T.
	top = 220
	left =200
	caption = &quot;Reset grid&quot;
	Procedure Click
	Thisform.Grid1.RecordSource=''
	Select * From myCursor WHERE VAL(address)>300 Into Cursor myCursor3
	Thisform.Grid1.RecordSource = &quot;myCursor3&quot;
	endproc
Enddefine

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thanks to all of you.
Now its working well. I just deleted my previous grid and again recreated it, and now it works well.

Thank you once again
 
Hello.

As Mike has told you, grid reconstruction is a very common phenomenon.

One way to avoid having the grid turn into a blank grey blob is to set its RecordSource to an empty string before running the SELECT and then resetting it afterward. Although this will work in the simplest of cases, it is not a solution I recommend. While it will keep your grid from losing its mind, the grid's columns still lose their ControlSources and any embedded controls. So, this works if your grid uses base class headers, base class text boxes, and displays the fields from the cursor in exactly the same order as they are SELECTed. Otherwise, you have to write a lot more code to restore all the things that get lost when the grid is re-initialized.

What I like to do is what I call a &quot;safe select&quot;. Use code like this to do the select into a temporary cursor, ZAP the grid's RecordSOurce, and then append from the temporary cursor. This works because ZAPing the grid's RecordSOurce does not close it.

WITH Thisform.Grid1
SELECT ( .RecordSource )
ZAP
SELECT Yada, Nada, Blah FROm SomeTable WHERE SomeCondition INTO CURSOR junk NOFILTER
SELECT ( .RecordSource )
APPEND FROM DBF( 'junk' )
USE IN junk
GO TOP IN ( .RecordSOurce )
.Refresh()
ENDWITH

-- Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top