Solved

React on item selected in TTreeView component

Posted on 2004-08-31
7
516 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

17 Experts available now in Live!

Get 1:1 Help Now