Page 1 of 1

TDBTree V.2, Master-Detail tree with 3 Datesets (3 levels)

Posted: Mon Dec 10, 2007 7:59 am
by 10547065
Hi,
how do I realize a TDBTree with 3 levels and 3 datasets.
First dataset is master of second and second is master of third.
I thougt to realize it with the DBLayout items, but I'm missing there the Detail property.
Any idea?

Posted: Tue Jan 15, 2008 12:34 am
by Tom
Hi,

TDBLayouts is the right way. Using db tables from the borland DBDemos:

Be sure to set up the tabels in master/detail relationship:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  tCustomers.Close;
  tOrders.Close;
  tItems.Close;
  tOrders.MasterSource := dsCustomers;
  tOrders.IndexName := 'CustNo';
  tOrders.MasterFields := 'CustNo';
  tItems.MasterSource := dsOrders;
  tItems.IndexName := 'ByOrderNo';
  tItems.MasterFields := 'OrderNo';
  tCustomers.Open;
  tOrders.Open;
  tItems.Open;
end;
Build the tree with DBLayout objects. A very basic example:

Code: Select all

procedure TForm1.ThreeTabelsClick(Sender: TObject);
var tmp : TDBLayout;
begin
    With DBTree1 do
    begin
      Layout.Clear;
      with DBTree1.Layout.Add do begin
        DataSet     := tCustomers; // some table
        Fields := 'CustNo;Company';
        Format.HorizTextAlign := htaLeft; //add some format
        Format.Border.Visible := False;
        Format.Font.Color := clBlue;
      end;
      with DBTree1.Layout.Add do begin
        DataSet := tOrders; // detail of tCustomers on CustNo
        Fields := 'OrderNo;AmountPaid';
      end;
      with DBTree1.Layout.Add do begin
        DataSet := tItems; // detail of tOrders on OrderNo
        Fields := 'ItemNo;PartNo;Qty';
      end;
      Refresh;
    end;
end;
Regards,
Tom