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

how to establish relation by code?

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
In Form1 I do create a cursor (parent).
From that Form1 another form (Form2)is called.
Datasession is same for Form1 and Form2.
In Form2 I need to set-up a relation with parent and some other tables (childs).

Can I get in Form2 the parent and child fields in one common grid?

I know relations can set by code but up to now my attempts failed.
-Bart
 
Hi Nifrabar:

Yes you can display multiple tables in a single grid.

I have never used data session so can not comment. But the following will acchive what you may need.


Prerequirement
1. Create your form(s).
2. Add Grid(s) to the form(s)
3. Create Tabble1, Table2
4. Table1 and Table2 have a common field called KEYFIELD
5. Also add another field called OTHERFIELD to Tables, could be any name.

Before calling Form1/Form2

use table1 in 0 alias table1
use table2 in 0 alias table2
* KEYFIELD is common in both table
select table2
index on KEYFIELD to t_table1
*
* Now set your relation
select table1
set relation to KEYFIELD into table2

* Now in the init() of your form you can continue
with thisform.grid1
.COLUMNCOUNT = 4
.DELETEMARK = .F.
.READONLY = .t.
.RECORDSOURCE = 'table1'


.column1.WIDTH = 60
.column1.CONTROLSOURCE = "table1.KEYFIELD"
.Column1.Header1.CAPTION = "Table1_Key"

.column2.WIDTH = 60
.coLUMN2.CONTROLSOURCE = "table2.KEYFIELD"
.Column2.Header1.CAPTION = "Table2_Key"
.Column2.CURRENTCONTROL = "Text1"
.Column2.SPARSE = .F.
.Column2.READONLY = .t.
.Column2.FONTSIZE = 9

.column3.WIDTH = 70
.column3.CONTROLSOURCE = "table1.OTHERFIELD"
.column3.Header1.CAPTION = "t1_OtherField"
.Column3.READONLY = .t.
.Column3.FONTSIZE = 9

.Column4.FONTSIZE = 10
.column4.WIDTH = 220
.column4.CONTROLSOURCE = "table2.OTHERFIELD"
.column4.Header1.CAPTION = "t2_OtherField"
.Column4.READONLY = .t.
.Column4.FONTSIZE = 10
.Column4.CURRENTCONTROL = "Text1"

ENDWITH


I hope it is clear


Nasib
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top