Page 1 of 1

Listbox as node in teetree

Posted: Sun May 14, 2006 1:36 pm
by 7729873
Hi

I've been thinking that it would be a very useful feature if one could "embed" or add the functionality of common visual components as nodes in a teetree. For example, is there a way of adding a drop-down listbox as a node to a teetree? Something like a drop-down lookup list in a DBGrid.

Posted: Mon May 15, 2006 4:31 pm
by Tom
Hi,

You can handle this in the AfterDraw event, eg:

Code: Select all

{ Draw a control at a node position... }
Procedure DrawControl(AControl:TControl; AShape:TTreeNodeShape);
var P:TPoint;
begin
  AControl.Visible:=AShape.Visible;
  if AControl.Visible then
  begin
    With AShape do P:=Tree.Canvas.Calculate3DPosition(X0,Y0,0);
    AControl.Left:=P.x;
    AControl.Top:=P.y;
  end;
end;

procedure TFormControls.Tree1AfterDraw(Sender: TObject);
begin
  DrawControl(Button1,TreeShape26);
  DrawControl(Edit1,TreeShape27);
  DrawControl(ComboBox1,TreeShape23);
  DrawControl(ListBox1,TreeShape16);
  DrawControl(RadioGroup1,TreeShape15);
  DrawControl(StringGrid1,TreeShape24);
end;

Another way might be to create your own shape descendants.

Kind regards,
tom

Super help!

Posted: Tue May 16, 2006 7:41 pm
by 7729873
Thank you very much, Tom :). Works beautifully.