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

Grid with some columns having a list of records

Status
Not open for further replies.

lastimosa

Instructor
Aug 13, 2002
15
PH
It is possible to have a single grid that catters a source of records of two or more diferent tables in which the other one is the parent and the other is a child.

I tried to look in the posted thread and read the books of visual foxpro but there was no specific answer.

Thanks
 
You can.

You have to set the controlsource property value of the individual columns to the table.column value you want.

Here's a raw example...

oForm = CREATEOBJECT("MyForm")
oForm.SHOW()
READ EVENTS

DEFINE CLASS MyForm AS FORM

WIDTH = 500
HEIGHT = 500
AUTOCENTER = .T.
CAPTION = "Grid with parent and child table"

* Add the grid

ADD OBJECT grdMultiTable AS GRID WITH ;
COLUMNCOUNT = 3, ;
DELETEMARK = .F., ;
WIDTH = 450, ;
HEIGHT = 400, ;
TOP = 5, ;
LEFT = 5, ;
column1.WIDTH = 50, ;
column2.WIDTH = 200, ;
column3.WIDTH = 200, ;
column1.CONTROLSOURCE = "parent_table.accountno", ;
column2.CONTROLSOURCE = "child_table.company", ;
column3.CONTROLSOURCE = "child_table.address"

ADD OBJECT chkAllChildRecs AS CHECKBOX WITH;
TOP = THIS.grdMultiTable.TOP+THIS.grdMultiTable.HEIGHT + 5, ;
LEFT = 5, ;
AUTOSIZE = .T., ;
CAPTION = "View all child records", ;
VALUE = .F.

* Create some cursors

PROCEDURE LOAD
CREATE CURSOR parent_table (accountno N(4,0))
INDEX ON PADL(ALLT(STR(accountno)),4,"0") TAG accountno
CREATE CURSOR child_table (accountno N(4,0), company c(20), address c(35))
INDEX ON PADL(ALLT(STR(accountno)),4,"0") TAG accountno

SELECT parent_table
SET RELATION TO PADL(ALLT(STR(accountno)),4,"0") INTO child_table

FOR i = 1 TO 1000
INSERT INTO parent_table (accountno) VALUES (i)

INSERT INTO child_table (accountno, company, address) VALUES ;
(i, "Company #"+ALLT(STR(i)), "Address #"+ALLT(STR(i)))

* Add a second child record every other parent record
IF MOD(i,2)==0
INSERT INTO child_table (accountno, company, address) VALUES ;
(i, "2nd Company #"+ALLT(STR(i)), "2nd Address #"+ALLT(STR(i)))
ENDIF

NEXT
GO TOP
ENDPROC

PROCEDURE DESTROY
CLEAR EVENTS
CLOSE DATA ALL
ENDPROC


* Add captions to grid headers

PROCEDURE grdMultiTable.INIT
THIS.COLUMNS(1).header1.CAPTION = "Account"
THIS.COLUMNS(2).header1.CAPTION = "Company"
THIS.COLUMNS(3).header1.CAPTION = "Address"
ENDPROC

* View all child records
PROCEDURE chkAllChildRecs.CLICK
IF THIS.VALUE
SET SKIP TO child_table
ELSE
SET SKIP TO
ENDIF
THISFORM.REFRESH()
ENDPROC
ENDDEFINE
'We all must do the hard bits so when we get bit we know where to bite' :)
 
Thanks Darrel, you have responded a very long answer and it seems to me I could not do it in a short time. I will try to understand the codes that you send.
 
Hi Lastimosa,

It is not that complicated as you may be thinking..

Let us go step by step..

Step1.
USE transaction ORDER myOrder IN 1 ALIAS tran
USE master ORDER masterId IN 2 ALIA master

SELECT tran
SET RELATION TO masterId INTO master

All the above codes is simple for you understand..

Step2. Now..

BROWSE FIELDS tran.Filed1, tran,.Field2, ;
master.Name1, master.Address1 ....

This is also simple... right? Yes.

Now create a grid with the grids columns/controls suitably in the place of the BROWSE FIELDS... and use it in the place of above BROWSE. (Tip.. use the 'alias.fieldname' as the control source)

That is it... :)

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Thanks Ramani for your brief answer, I will try this code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top