[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Index of TTreeView's SubItem

Posted on 2003-11-11
7
Medium Priority
?
303 Views
Last Modified: 2010-04-05
+ABC
|    |__ SubA
|    |__ SubB
|
+XYZ
     |__ SubX
     |__ SubY

When item "ABC" is selected, TTreeView.Selected.Index returns 0; when SubItem "SubA" or "SubB" is selected, it also returns 0 !!  So how can I differentiate which item/subitem is being selected ??

Thank You.

raymng
0
Comment
Question by:Raymond
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9721033
this could not be

how do you do evaluate the index
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9721132
raymng,
  You would have to recursively traverse the parents of the selected treenode till you get a nil parent. Something like this (Where the GetIndexStr procedure will build a comma-separated index string for you):

procedure TForm1.Button1Click(Sender: TObject);
Var
  MyStr: String;

Procedure GetIndexStr(MyNode: TTreeNode; Var MyIndexStr:String);
begin
 If MyNode.Parent <> nil then
   GetIndexStr(MyNode.Parent, MyIndexStr)
 Else
   MyIndexStr := '';
 MyIndexStr := MyIndexStr +','+inttostr(MyNode.index);

end;

begin

  ShowMessage(IntToStr(TreeView1.Selected.Index));
  GetIndexStr(TreeView1.Selected, MyStr);
  ShowMessage(MyStr);

end;
0
 
LVL 5

Expert Comment

by:snehanshu
ID: 9721169
Or you could get the indexes in an array like:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  AOI = Array Of Integer;
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
Var
  MyStr: String;
  MyAry: AOI;
  i: Integer;

Procedure GetIndexAry(MyNode: TTreeNode; Var Ary: AOI);
begin
 If MyNode.Parent <> nil then
   GetIndexAry(MyNode.Parent, Ary)
 Else
   SetLength(Ary, 0);

 SetLength(Ary, Length(Ary) + 1);
 Ary[High(Ary)] := MyNode.Index;

end;


begin

//  ShowMessage(IntToStr(TreeView1.Selected.Index));
  GetIndexAry(TreeView1.Selected, MyAry);
  ListBox1.Items.Clear;
  For i := low(MyAry) To High(MyAry) Do
  Begin
    ListBox1.Items.Add(inttostr(MyAry[i]));
  End;



end;

end.
0
Technology Partners: 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 27

Expert Comment

by:kretzschmar
ID: 9721172
use absoluteIndex instead index to get an unique index
0
 

Author Comment

by:Raymond
ID: 9721278
kretzschmar:

Could you please give me an example on how to use the "AbsoluteIndex" ?

raymng
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 600 total points
ID: 9721299
well, its simple

procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage(inttostr(treeview1.selected.absoluteindex));
end;

meikl ;-)
0
 

Author Comment

by:Raymond
ID: 9721541
Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

872 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