Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Expanding a TTreeView

After using the ExpandAll command I want the first item in the TTreeView to be shown in the window. It's Not. What happens is the Tree expands and then scrolls to the bottom. Then end of the expanded tree is visible. The first item of the tree still has focus but it isn't displayed. I want to basically lock the position of the top of the tree and expand witout changing the contents of what is currently displayed on the screen.
0
mbritt120898
Asked:
mbritt120898
  • 8
  • 5
  • 2
  • +1
1 Solution
 
williams2Commented:
Ok, this is simple - try this on the expanded event:

procedure TForm1.TreeExpanded(Sender: TObject; Node: TTreeNode);
begin
  Tree.selected.MakeVisible
end;


Regards,
Williams
0
 
williams2Commented:
..Or maybe try this:

The selected Item could be nil, which would raise an exception.

procedure TForm1.TreeExpanded(Sender: TObject; Node: TTreeNode);
begin
  If Tree.Selected=nil then Tree.Selected:= Tree.TopItem;
  Tree.selected.MakeVisible
end;
0
 
mbritt120898Author Commented:
Neither one of the fixes worked. In your second answer where you said [if Tree.Selected=nil] has no bearing because in my tree the first Node has focus. The first item in my Tree which is at Level=0. When I expand the tree you can see the scroll bar to the right at the bottom of the window. If I scroll back up using the scroll bar you can see that the first item in the Tree is Focused. I want the TOP of the tree to be displayed, not the result of expanding the tree (which is the bottom of the tree).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
williams2Commented:
Shouldn't that be simple enough?

Like:

Tree.TopItem.MakeVisible; (..Or TreeView1.TopItem.MakeVisible;)

Or do you also want to remove the scrollbars???

Regards,
Williams
0
 
mbritt120898Author Commented:
My Tree has the Focus all the time. I can see that the first Parent node has focus because it has the hightlighted box around it. I have a button on my toolbar that performs the following code:

procedure TfMain.miExpandAllClick(Sender: TObject);
begin
 with TreeNT1 do
 begin
  Items.BeginUpdate;
  FullExpand;
  Items.EndUpdate;
 end;
end;

After I do this and all the branches are opened, my screen shows the contents of the bottom of the tree list. If I hit the down arrow key one time my cursor moves to the second item in the list (from the very top of the list) not the top item currently showing on the screen.  So by this I know that even during the ExpandAll command my first Parent node in the tree has focus and still has focus after the tree is expanded. However, It is not displayed in the window.  I'll give you an analogy. It would be the same thing as viewing a Microsoft Word document that was 4 pages long and you were looking at the 4th page on the screen when you really wanted to be looking at page 1.

Hope this helps.

Michael


0
 
mbritt120898Author Commented:
When the Tree is Collaped there are no scrollbars because my text doesn't exceed the height of the screen. When I expand All the scrollbars appear. This is normal and expected behavior. I just don't want to have to scroll back up to the top of the document.
0
 
williams2Commented:
Ok, I made a wrong entry at the previous attempt.

To make the first Item in the TreeView visible at all time when you expand, this is what you want:

procedure TfMain.miExpandAllClick(Sender: TObject);
begin
 with TreeNT1 do
 begin
  Items.BeginUpdate;
  FullExpand;
  Items[0].MakeVisible;
  Items.EndUpdate;
 end;
end;

Try this one!

Regards,
Williams
0
 
mbritt120898Author Commented:
Awesome, it worked. It's amazing how close I was in my own code. Just adding 1 line made the difference. I guess I never thought to look for the "MakeVisible" event. I kept looking for something like "Visible", "Selected", etc...

Thanks,

Michael
0
 
bruintjeCommented:
so williams gets his points for providing the answer....?

:O)
0
 
williams2Commented:
You are welcome Michael, should it be another time,
These things can be a little tricky some times. First I tried using Treeviews, I found it somehow strange.

Regards,
Williams
0
 
williams2Commented:
Sorry br(UINT)je, I had to eat some dinner first, we danes ought to eat sometimes too, hehe :-)

Regards,
Williams
0
 
bruintjeCommented:
it's Ok, Williams I must get some sleep by now, we Dutchies do that sometimes too.

Hope you had a good meal..
0
 
williams2Commented:
And so mr mbritt, is there any particular reason why you rejected my answer to your question, when I have been so kind to solve your problem?

Regards,
Williams
0
 
viktornetCommented:
I'm just wondering why Michael rejected Williams' answer when it was completely right... it was even awesome . o O ????

Cheers,
Viktor
0
 
mbritt120898Author Commented:
Williams2,

I did not reject your answer the third time around. I already accepted the answer as Excellent. You should have received 200 points for you help. Is this not the case?
0
 
viktornetCommented:
mbritt, you have clicked on that radio button for Excellent, but you have pressed Reject instead of Accept so that's why it is rejected and now accepted.. williams should answer once again and then you have to press the button that says ACCEPT after you choose an option in your case Excellent...

Cheers,
Viktor
0
 
williams2Commented:
Hmmm.. This could maybe raise the question, whether the answering system could use some improvements :-)

That's ok mbritt, I assumed that some error happened some way or another.

Let's go try again, and you'll get some free experiences in how the system works.

Cheers,
Williams
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now