[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

React on item selected in TTreeView component

Posted on 2004-08-31
7
Medium Priority
?
532 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 225 total points
ID: 11942395
What about OnChange and OnChanging
0
 
LVL 13

Accepted Solution

by:
BlackTigerX earned 300 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 225 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

650 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