Solved

Expanding a TTreeView

Posted on 1998-12-11
17
2,424 Views
Last Modified: 2008-02-01
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
Comment
Question by:mbritt120898
  • 8
  • 5
  • 2
  • +1
17 Comments
 
LVL 3

Expert Comment

by:williams2
ID: 1350679
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
 
LVL 3

Expert Comment

by:williams2
ID: 1350680
..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
 

Author Comment

by:mbritt120898
ID: 1350681
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
 
LVL 3

Expert Comment

by:williams2
ID: 1350682
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
 

Author Comment

by:mbritt120898
ID: 1350683
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
 

Author Comment

by:mbritt120898
ID: 1350684
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
 
LVL 3

Expert Comment

by:williams2
ID: 1350685
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
 

Author Comment

by:mbritt120898
ID: 1350686
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 44

Expert Comment

by:bruintje
ID: 1350687
so williams gets his points for providing the answer....?

:O)
0
 
LVL 3

Expert Comment

by:williams2
ID: 1350688
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
 
LVL 3

Expert Comment

by:williams2
ID: 1350689
Sorry br(UINT)je, I had to eat some dinner first, we danes ought to eat sometimes too, hehe :-)

Regards,
Williams
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1350690
it's Ok, Williams I must get some sleep by now, we Dutchies do that sometimes too.

Hope you had a good meal..
0
 
LVL 3

Expert Comment

by:williams2
ID: 1350691
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1350692
I'm just wondering why Michael rejected Williams' answer when it was completely right... it was even awesome . o O ????

Cheers,
Viktor
0
 

Author Comment

by:mbritt120898
ID: 1350693
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1350694
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
 
LVL 3

Accepted Solution

by:
williams2 earned 200 total points
ID: 1350695
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now