Solved

React on item selected in TTreeView component

Posted on 2004-08-31
7
528 Views
Last Modified: 2010-04-05
I have created a TTreeView component on a form
Now, when the user 'navigates' through this structure, I want to be able to do some work when individual 'items' are highlighted.
One way is to code the event OnClick, but I am surprised that there is no such kind of event OnSelected that I can use when, for example, the user simply uses the down and up arrows to navigate.
Is there such event or an equivalent trick ?
0
Comment
Question by:LeTay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Assisted Solution

by:mottor
mottor earned 75 total points
ID: 11942395
What about OnChange and OnChanging
0
 
LVL 13

Accepted Solution

by:
BlackTigerX earned 100 total points
ID: 11943129
as mottor says
OnChange will do the trick (Occurs whenever the selection has changed from one node to another.)

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
  Label1.Caption:=Node.Text; //here's the Node you're in
end;
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11943271
Which component are you using ? the Delphi one or the Virtual Treeview from www.delphi-gems.com ? (I prefer the later) but if its the normal delphi one, then

try

procedure TForm1.TreeView1Click(Sender: TObject);
Var
        Mynode: TTreeNode;
begin
   Mynode:= TreeView1.Selected;
end;

to get hold of the node when the user clicks on the treeview, or if you want get the node that has been changed/edited then use the ONchange event, which gives the node that has been changed (see below).  However that wont be fired if the user simply clicks the tree.

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin

end;

If you need to get news of the user changing the node they have selected, such as by using the arrow keys or sometihng then its probably easiest to dump a TTimer on the form set the interval for about a quater of a second (250) then have the following code

{$R *.dfm}

Var
        LastSelected: TTreeNode;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
   If (LastSelected <> TreeView1.Selected) then
   Begin
      Lastselected:= TreeView1.Selected;
      HELPanotherNodeHasBeenSelected(LastSelected);
   end;
end;

procedure TForm1.HELPanotherNodeHasBeenSelected(node: TTreeNode);
Begin
// what you going to do about it goes here ;-)
end;

hope that helps, If you need clarifaction then just ask

David
0
Technology Partners: 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!

 

Author Comment

by:LeTay
ID: 11943390
That OnChange is the answer.
I coded my little stuff there (do some work...) but now the selected item is not highlighted anymore.
I suppose I have to highlight it myself, but how ?
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 75 total points
ID: 11943833
>That OnChange is the answer.
yep
>but now the selected item is not highlighted anymore
what is your stuff?
0
 
LVL 6

Expert Comment

by:bpana
ID: 11944189
set HideSelection to False;
0
 

Author Comment

by:LeTay
ID: 11949799
Indeed the code I executed is showing another form with details of the selected item.
So the primary form containing the TTreeView "looses" the focus.
I just add to give it the focus back -> Form1.SetFocus and now it works
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 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