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?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom KnowltonWeb developerAuthor Commented:
Edited text of question.
0
Tom KnowltonWeb developerAuthor Commented:
Edited text of question.
0
mhervaisCommented:
listening
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

CalvinDayCommented:
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.
0
mhervaisCommented:
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.
0
mhervaisCommented:
much better than my messy idea
0
VenneCommented:
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.
0
philipleighsCommented:
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.
0
Tom KnowltonWeb developerAuthor Commented:
phillipleighs:

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

Tom
0
philipleighsCommented:
Hi Tom,

Glad to help and thanks for the points!

Cheers,
Phil.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
You're welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.