Solved

Index of TTreeView's SubItem

Posted on 2003-11-11
7
292 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:raymng
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 27

Expert Comment

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

Author Comment

by:raymng
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 150 total points
ID: 9721299
well, its simple

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

meikl ;-)
0
 

Author Comment

by:raymng
ID: 9721541
Thanks.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now