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

One-to-many relation and child records in a grid

Status
Not open for further replies.

mibosoft

Programmer
Jul 23, 2002
106
SE
Hi,
I would like my form (in a formset) to show parent records in text fields and child records in a grid but I simply can't get it to work. I set up the relation like (I don't use the database designer):

sele FAKT_POST && child
set order to tag REF_NR
sele FAKT && parent
set order to tag REF_NR
set relation to REF_NR into FAKT_POST

The problem is that the grid is stuck on one child record regardless of what record the parent shows. I'm using skip controls (vcr from ffc) to move in the parent table.

I have tried with and without entering "Linkmaster" and relationalexpr" in the grid properties. I that needed or is the same as setting up a relation?

I thought this would be simple :-( Can anyone give me a hint?

Thanks,
Micael
 

Check SET SKIP TO in the help file.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Make sure you have a grid with the parent in it - and keep it hidden!

Regards

Griff
Keep [Smile]ing
 
Hi Micael,

Is the control doing a REFRESH after the pointer is moved?

Regards,

Mike
 
Hi again,
Thanks for your answers. The example below works if you put in a .prg file but when trying to make the same in a formset with the form designer, it doesn't work :-( Aonother hour or two of trial and error and it might work :)
/Micael

* Creates parent table with values a and b in Name field
select parent
create table parent free (namn C(1), val C(10))
insert into parent values ('a', 'Parent.a1')
insert into parent values ('b', 'Parent.b1')
index on namn tag TAGNAME_P && The tag name is irrelevant

select child && Child will have two a's and two b's
create table child free (namn C(1), val C(10))
insert into child values ('b', 'Child.b1')
insert into child values ('b', 'Child.b2')
insert into child values ('a', 'Child.a1')
insert into child values ('a', 'Child.a2')
index on namn tag TAGNAME_C && The tag name is irrelevant

* Relation
select parent
set relation to namn into child
*set skip to child

* Show the form and it's controls
public OFORM1
OFORM1=newobject("form1")
OFORM1.addobject('fwd','my_fwd')
OFORM1.addobject('rew','my_rew')
OFORM1.addobject("text","mytext")
OFORM1.addobject('grid1','myGrid')
OFORM1.show
return

*******************************************
* Controls

define class FORM1 as form
visible=.t.
docreate = .t.
enddefine

define class MY_FWD as commandbutton
visible=.t.
autosize = .t.
left = 50

procedure click
if !eof()
skip
thisform.refresh
endif
endproc

enddefine

define class MY_REW as commandbutton
visible=.t.
autosize = .t.

procedure click
if !bof()
skip -1
thisform.refresh
endif
endproc

enddefine


define class MYGRID as grid
visible=.t.
columncount = 2
left = 50
top = 50
* recordsource="child"
* linkmaster="parent"
* relationalexpr="namn"
* childorder="namn"

procedure init
this.recordsource="child"
with this.COLUMN1
.controlsource="child.namn"
endwith
with this.COLUMN2
.controlsource="child.Val"
endwith
endproc
enddefine

define class MYTEXT as textbox
visible=.t.
left = 150
controlsource="parent.namn"
enddefine
 
NormanBates

I cannot seems to duplicate your problem.
[ol][li]I create a form.[/li]
[li]Put a grid on it.[/li]
[li]Add a command button on the form.[/li]
[li]In the click event of the button I put:
Code:
SELECT parent 
SKIP
thisform.Refresh()
[/li]
[li]Set the grid recordsource to the child.[/li]
[li]In the load of the form I put:
Code:
create table parent free (namn C(1), val C(10))
insert into parent values ('a', 'Parent.a1')
insert into parent values ('b', 'Parent.b1')
index on namn tag TAGNAME_P     && The tag name is irrelevant
create table child free (namn C(1), val C(10))
insert into child values ('b', 'Child.b1')
insert into child values ('b', 'Child.b2')
insert into child values ('a', 'Child.a1')
insert into child values ('a', 'Child.a2')
index on namn tag TAGNAME_C     && The tag name is irrelevant
SELECT parent
SET RELATION TO [b]parent.namn[/b] INTO child
[/li]
[li]Run the form and click the button and the child follows the parent record.[/li][/ol]




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,
Now, it works. Actually I think there where two reasons to why it didn't work earlier:

1. Before, I set up each columns controlsource, caption, width etc in the grid init event but the grids recordsource in the properties dialog. I have now moved also the recordsource setup (this.recordsource=...) to the init event. Seems to be kind of a timing problem at init.

2. The relational expression (REF_NR) was indexed:
index on val(REF_NR) tag REF_NR
Now changed into:
index on REF_NR tag REF_NR

I'm glad that it works now. Thanks for taking time trying to help me.

/Micael


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top