LeTay
asked on
React on item selected in TTreeView component
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 ?
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 ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ?
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 ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
set HideSelection to False;
ASKER
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
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
try
procedure TForm1.TreeView1Click(Send
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(Sen
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:
begin
If (LastSelected <> TreeView1.Selected) then
Begin
Lastselected:= TreeView1.Selected;
HELPanotherNodeHasBeenSele
end;
end;
procedure TForm1.HELPanotherNodeHasB
Begin
// what you going to do about it goes here ;-)
end;
hope that helps, If you need clarifaction then just ask
David