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

using SET RELATION to limit Grid data - not working! 1

Status
Not open for further replies.

kazl

Programmer
Dec 9, 2002
68
GB
Hi All. I've a general purpose grid program used sometimes for whole files and other times for set data.

Want to limit the data in grid according to ACCOUNTNO field. Using SET FILTER will be too slow so tried using SET RELATION from the customer file (SET RELATION TO accountno INTO vehicles) But it doesn't work and I can still scroll past the start and end of the data into other accounts.

SET RELATION worked perfectly in FPW26 but when I use it even to just browse two tables I can still see other data in the child table. I'm using VFP6.

Is there another way I can limit to one account in the grid? I've have also tried testing with
RecordSourceType = 1
RecordSource = "vehicles"
LinkMaster = "CUSTOMER.accountno"
RelationalExpr = "accountno"
But don't really understand them and they make no difference. Any ideas/suggestions please (apart from using a Query)

Thanks. Kaz
 
HI

1. SELECT PARENT
2. SET RELATION TO CHILD on Key field
3. Make sure the default alias is the PARENT
4. The Grids records source should be child table
5. When you skip thru the records, Grid will sure to follow the PARENT

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

 
Ramani

I created a test form to prove it works and that's great. But in code it still allows me to scroll to unrelated data. I can't see why - can you see where I am wrong?

Code:
maccno = "APR002"
select 2
USE VEHICLES INDEX VEHICLES, VEHREGNO
select 1
use customer index customer
SET RELATION TO accountno INTO vehicles
seek maccno
select 2
myHeight = 242
*- Relation Info
myLink = "Customer"
myChild = "Vehicles"
mySource = "Vehicles"
myRelate = "Accountno"
*- field list and headings for Grid 
myTitle = "Update Customer Vehicle Records"
myFields = "ACCOUNTNO,REGNO,MAKE,MODEL"
myROlist = "REGNO"
myHeader = "A/C No,Reg. No,Make,Model"
ALINES(laHeader,chrtran(myHeader,",",chr(10)))

SET PROCEDURE TO MyGrids
oGridForm=NEWOBJECT("gsGridForm",'','',myFields)
IF TYPE("oGridForm") = "O" AND NOT ISNULL(oGridForm)
	oGridForm.Show
	RELEASE oGridForm
ENDIF
RETURN


*-- CLASS DEFS FOR OTHER PRGS FOR GRIDS
PROCEDURE MyGrids

*-- GRID FORM
DEFINE CLASS gsGridForm AS form
  Height = myHeight
  AutoCenter = .t.
  Width = 820
  DoCreate = .T.
  Caption = myTitle
  Name = "gsGridForm"
  WindowType = 1
  inrecno = 0

  ADD OBJECT grid1 AS grid WITH ;
    Height = myHeight-30, ;
    Left = -12, ;
    Top = 0, ;
    Width = 832, ;
    Name = "Grid1", ;
    DeleteMark = .F., ;
    HighlightRow = .T., ;
    ReadOnly = .F., ;
    RecordSourceType = 1, ;
    ChildOrder = myChild, ;
    LinkMaster = myLink, ;
    RecordSource = mySource, ;
    RelationalExpr = myRelate

  PROCEDURE Init
    PARAMETERS tcFields
    IF PARAMETERS() < 1 .or. len(trim(tcfields)) = 0
      WAIT WINDOW &quot;Cannot create screen with no parameters!&quot;
      RETURN .f.
    ENDIF
    LOCAL pCount
    tcFields = chrtran(tcFields,&quot;,&quot;,chr(10))
    pCount = ALINES(laFields,tcFields)
    WITH ThisForm.Grid1
      .FontName = &quot;Tahoma&quot;
      .FontSize = 10
      .FontBold = .F.
      .ColumnCount = pCount
      FOR I=1 TO pCount
        .Columns(I).Tag = laFields(i)
        .Columns(I).ControlSource = laFields(i)
        .Columns(I).Width = 68
        if type(laFields(i)) = &quot;D&quot;
          .Columns(I).Alignment = 2		&& middle center
          .Columns(I).InputMask = &quot;##/##/##&quot;
        endif
        if type(laFields(i)) = &quot;N&quot;
          .Columns(I).Alignment = 1		&& middle right
          .Columns(I).InputMask = &quot;999999.99&quot;
        endif
        if type(&quot;myROlist&quot;) # &quot;U&quot;
          .Columns(I).ReadOnly = laFields(i)$myROlist
        endif
        if type(&quot;myHeader&quot;) # &quot;U&quot;
          .Columns(I).Header1.Caption = laHeader(i)
        endif
        if type(laFields(i)) = &quot;C&quot;
          .Columns(I).Width = len(laFields(i))*15
        endif
      ENDFOR
      .SetFocus()
    ENDWITH
  ENDPROC

ENDDEFINE

 
HI

I did not go thru complete code..
But the problem could be in this..


maccno = &quot;APR002&quot;
select 2 && Child table and browsed in Grid
USE VEHICLES INDEX VEHICLES, VEHREGNO
select 1 && parent table..
use customer index customer
SET RELATION TO accountno INTO vehicles
seek maccno
select 2 && This is where I suspect

After a relation is set .. keep your default alias as parent. :)
ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Ramani - You're a champion. I changed it to..

Code:
select 1
use customer index customer
select 2
USE VEHICLES INDEX VEHICLES, VEHREGNO
SET PROCEDURE TO MyGrids
oGridForm=NEWOBJECT(&quot;gsGridForm&quot;,'','',myFields)
IF TYPE(&quot;oGridForm&quot;) = &quot;O&quot; AND NOT ISNULL(oGridForm)
	select 1
	SET RELATION TO accountno INTO vehicles
	seek maccno
	oGridForm.Refresh()
	oGridForm.Show
	RELEASE oGridForm
ENDIF
RETURN

... and it works. Thank you.

KazL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top