[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1083
  • Last Modified:

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?
0
Tom Knowlton
Asked:
Tom Knowlton
  • 4
  • 3
  • 2
  • +2
1 Solution
 
Tom KnowltonWeb developerAuthor Commented:
Edited text of question.
0
 
Tom KnowltonWeb developerAuthor Commented:
Edited text of question.
0
 
mhervaisCommented:
listening
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
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
 
Tom KnowltonWeb developerAuthor Commented:
You're welcome
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now