?
Solved

treeview naviagtion

Posted on 2003-03-31
15
Medium Priority
?
274 Views
Last Modified: 2010-04-06
im 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.
0
Comment
Question by:deceptionx
  • 4
  • 3
  • 3
  • +3
13 Comments
 
LVL 3

Accepted Solution

by:
emadat earned 100 total points
ID: 8241514
Look at this article. It covers the TreeView from A to Z
http://users.iafrica.com/d/da/dart/zen/Articles/TTreeView/TreeView.html
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 100 total points
ID: 8243614
simple use the onChange-Event of the TTreeView

meikl ;-)
0
 

Assisted Solution

by:antonio_fortuny
antonio_fortuny earned 100 total points
ID: 8243797
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,Printers, ImgList, Menus,
  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: TObject; Button: TMouseButton;
  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.Level);
if Button = mbRight then begin
  Tree1click(Sender);
  PopMenu.Popup(X+(Sender as TTreeView).ClientOrigin.x,Y+(Sender as TTreeView).ClientOrigin.y);
  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(params);
    end;
  1: begin        // click on level 1
    end;
  ...
  end;

procedure TF1.Tree1Collapsing(Sender: TObject; Node: TTreeNode;
  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: TObject; Node: TTreeNode;
  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,VK_HOME,VK_LEFT,VK_UP,VK_RIGHT,VK_DOWN] then
    Tree1Click((Sender as TTreeView));
  end;
end;

Enjoy.

Antonio.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:nafeelm
ID: 8244126

your question is still not clear to me!

could you explain it in detail please ?

0
 

Author Comment

by:deceptionx
ID: 8249092
jsut give me a simple way to click an item in a treeview and give it an event. its as simple as that.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8250864
>simple use the onChange-Event of the TTreeView

;-)
0
 
LVL 1

Expert Comment

by:nafeelm
ID: 8252571

could you just explain me your logic, as if what you want to do using the TTreeView component ?

do u want to assign an event to the TTreeView component or its TreeNodes or the individual TreeNode!

0
 

Author Comment

by:deceptionx
ID: 8252849
yes thats it, and could you possably give me an of the coding of for the OnChange-Event...
0
 

Author Comment

by:deceptionx
ID: 8252853
example of the coding << what i meant to say...
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8252878
a sample

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
  //do your action here based on the Node parameter
  showmessage('It was Navigated to '+Node.Text);
end;

meikl ;-)
0
 
LVL 1

Expert Comment

by:nafeelm
ID: 8253164

i think 'kretzschmar' above sample example should be of help to you!
0
 

Author Comment

by:deceptionx
ID: 8281100
I am using delphi 7 that procedure doesnt work... :-/
0
 

Expert Comment

by:CleanupPing
ID: 9316524
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.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

609 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