?
Solved

treeview naviagtion

Posted on 2003-03-31
15
Medium Priority
?
271 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
[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
  • 4
  • 3
  • 3
  • +3
15 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

765 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