Solved

React on item selected in TTreeView component

Posted on 2004-08-31
7
522 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection between libmysql.dll and MySQL Versions 7 99
Help on project with Soap 10 54
Dev Express grid collapse 2 45
Reconfigure Delphi Install? 2 51
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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