simple use the onChange-Event of the TTreeView
meikl ;-)
Main Topics
Browse All Topicsim trying to make a program that allows you to navigate throuh by clicking a node on a treeview. I just need an example code of clicking a node and giving it an event.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This an abstract of a DB manager using a tree view.
unit Dict1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ToolWin, StdCtrls, Buttons,db,DBTables,Printe
ExtCtrls, DBCtrls, Mask,Login7b,UtilsG3, ActnList,AForStd3;
type
TF1 = class(TForm)
StatusBar1: TStatusBar;
...
Tree1: TTreeView;
...
procedure Tree1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Tree1Click(Sender: TObject);
procedure Tree1Collapsing(Sender: TObject; Node: TTreeNode;
var AllowCollapse: Boolean);
procedure Tree1Expanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
procedure Tree1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Tree1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
...
end;
Useful function:
function GetNodeIndex(node: TTreeNode; mousecoord: TPoint): TTreeNode;
implementation
procedure TF1.Tree1MouseDown(Sender:
Shift: TShiftState; X, Y: Integer);
var
n: TTreeNode;
tp: TPoint;
begin
tp.X := X;
tp.Y := Y;
n := GetNodeIndex((Sender as TTreeView).Items[0],tp);
if n = nil then
n := (Sender as TTreeView).Selected
else
(Sender as TTreeView).Selected := n;
if (n.Level = 1) and (not n.HasChildren) then
DoWhatEverOnThisLevel(n.Le
if Button = mbRight then begin
Tree1click(Sender);
PopMenu.Popup(X+(Sender as TTreeView).ClientOrigin.x,
end;
end;
procedure TF1.Tree1Click(Sender: TObject);
var
n: TTreeNode;
begin
if (Sender as TTreeView).Enabled = False then
exit;
n := (Sender as TTreeView).Selected;
case n.Level of
0: begin // click on Root TreeItem
DoAnythingForRootLevel(par
end;
1: begin // click on level 1
end;
...
end;
procedure TF1.Tree1Collapsing(Sender
var AllowCollapse: Boolean);
begin
// what to do when a node will be collapsed
if Node.Level = 0 then
exit;
Tree1.Selected := Node;
end;
procedure TF1.Tree1Expanding(Sender:
var AllowExpansion: Boolean);
begin
// what to do when a node will be expanded
if Node.Level = 0 then
exit;
Tree1.Selected := Node;
end;
procedure TF1.Tree1KeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
var
n: TTreeNode;
begin
if (Sender is TTreeView) and ((Sender as TTreeView).Focused) then begin
n := (Sender as TTreeView).Selected;
case Key of
VK_INSERT:
InsertItem(n);
VK_DELETE:
DeleteItem(n);
VK_RETURN: begin
Tree1Click(Sender as TTreeView);
end;
end;
end;
end;
procedure TF1.Tree1KeyUp(Sender: TObject; var Key: Word;Shift: TShiftState);
begin
if (Sender is TTreeView) and ((Sender as TTreeView).Focused) then begin
if Key in [VK_PRIOR,VK_NEXT,VK_END,V
Tree1Click((Sender as TTreeView));
end;
end;
Enjoy.
Antonio.
deceptionx:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
Business Accounts
Answer for Membership
by: emadatPosted on 2003-03-31 at 13:43:03ID: 8241514
Look at this article. It covers the TreeView from A to Z /da/dart/z en/Article s/TTreeVie w/ TreeView .html
http://users.iafrica.com/d