Page 1 of 1

Make node visible in TTree

Posted: Mon Oct 21, 2013 2:23 pm
by 10546756
Hello!

I have a TTree with a lot of nodes in it. How can I programatically make a certain node to be visible in the Tree? (Inside the visible area of the tree)

Best regards, Mikael

Re: Make node visible in TTree

Posted: Wed Oct 23, 2013 3:05 pm
by yeray
Hi Mikael,

Can't you do this with a TTreeNodeShape?

Code: Select all

TreeNodeShape1.Visible:=true;

Re: Make node visible in TTree

Posted: Wed Oct 23, 2013 7:12 pm
by 16567478
Sorry, I explained badly... In my TTree I have a tree structure displayed, like in Explorer. Now I want my TTree to scrool so that my current node becomes visible.

best regards, Mikael

Re: Make node visible in TTree

Posted: Fri Oct 25, 2013 1:33 pm
by yeray
Hi Mikael,

In the following example, we have a root node with a hundred childs.
If you want you can scroll down dragging the Tree with the right mouse button, or you can use the scrollbar for the same.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    TreeNodeShape1: TTreeNodeShape;
begin
  TreeNodeShape1:=Tree1.AddRoot('Root');
  TreeNodeShape1.Expanded:=true;

  for i:=0 to 100 do
    TreeNodeShape1.AddChild('Child ' + IntToStr(TreeNodeShape1.Children.Count+1));
end;
If you are looking for a function to force the scroll to a determined child by code, you can use View3DOptions.VertOffset:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    TreeNodeShape1: TTreeNodeShape;
begin
  TreeNodeShape1:=Tree1.AddRoot('Root');
  TreeNodeShape1.Expanded:=true;

  for i:=0 to 100 do
    TreeNodeShape1.AddChild('Child ' + IntToStr(TreeNodeShape1.Children.Count+1));

  TreeNodeShape1.Children[49].Selected:=true;

  Tree1.Draw;
  Tree1.View3DOptions.VertOffset:=-TreeNodeShape1.Children[49].Y0;
end;