views:

266

answers:

1

This has always bugged me to what is the best way to do the following...

with a simple one to many db, when you have 2 tables/grids on a form and the 2nd one filtered by the first.

where is the best place to put the filter code
ie:

procedure TForm1.tblCustormersAfterScroll(DataSet: TDataSet);
begin
  if tblCustormersCustormerID.AsString <> '' then
   begin
     tblCustormersThings.Filter := 'CustormerID = ' + tblCustormersCustormerID.AsString;
     tblCustormersThings.Filtered := true;
   end;
end;

AfterScroll seems to work most of the time, but donst get fired on some events eg after posting. Normally i would have a procedure to do the filter update and put it where ever it seems to be needed.

But i was wondering if there is a better way, this seems like simply stuff delphi should know about...

I Dont think it matters but im Using Delphi7 and NexusDB1

+4  A: 

You should set MasterSource and master fields properties on "many" side.

It is called Master - Detail relationship, and you should check with NexusDB help for a way to crate this relation ship between tables.

If your table supports indexes, than you can create index on CustomerID and also use SetRange() method.

The way you set Filter is the slowest one.

dmajkic
I knew there had to be a better way, Nexusdb tables are descended from Tdataset so the MasterSource and MasterFields where there, I just had to fix up some of the indexs. Thankyou
Christopher Chase