Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

Moving scrollbar to top of TTreeView after expanding the entire tree

I have a TTreeView with lots of stuff.  When I click on the button to expand the tree, it expands, but the scrollbar is left at the bottom of the TTreeView when the tree is done expanding.  After the Tree expands, I want to move the scrollbar back up to the top of the Tree listing.

How is this done?
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

Edited text of question.
Edited text of question.
Avatar of mhervais
mhervais

listening
From delphi help:

TopItem

Specifies the topmost node that appears in the tree view.

property TopItem: TTreeNode;

Description

When TopItem is changed, the tree view scrolls vertically so that the specified node is topmost in the list view.
To be frank, I have an idea, but I find it messy. I give it to you for what it is : you could simulate the click of the mouse by sending the appropriate messages to the ttreeview window.
much better than my messy idea
you can write:
with yourtreeview do begin
  selected:=items[0];
end;
it like calvinday said, it move current selection ,and the scrollbar will move to the top.
Try this:

TreeView1.Items[0].MakeVisible;

If you see it scroll to the bottom, then quickly to the top again, then use BeginUpdate and EndUpdate to prevent the redraw.

TreeView1.Items.BeginUpdate;
try
  TreeView1.FullExpand;
  TreeView1.Items[0].MakeVisible;
finally
  TreeView1.Items.EndUpdate;
end;


Cheers,
Phil.
phillipleighs:

You get the points.  Your code worked just as you typed it.  Please repost your comment as an answer.

Tom
ASKER CERTIFIED SOLUTION
Avatar of philipleighs
philipleighs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You're welcome