?
Solved

Select an item in the TTreeView

Posted on 2006-05-30
7
Medium Priority
?
465 Views
Last Modified: 2010-04-04
Hi,

I`m new using TTreView. Could u tell me how do I select an item from the TreeView ? I`m confused with the TTreeNode ...

Thanks,
0
Comment
Question by:crystyan
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 580 total points
ID: 16794043
procedure TForm1.Button1Click(Sender: TObject);
var
    node, tempnode: ttreenode;
begin
// display the text in teh currently selected tree node
    showmessage('Currently selected node: ' + TreeView1.Selected.Text);
// "select" the 3 node (using absoluteindex) and display the text
    Treeview1.Selected := Treeview1.Items[2];
    showmessage('3rd node (absoluteindex): ' + TreeView1.Selected.Text);
// "select" the "Root" node and display the text
    Treeview1.Selected := Treeview1.Items[0];
    showmessage('1st node:' + TreeView1.Selected.Text);
// "select" the 1st child of the root node and display the text
    node := Treeview1.Items[0];
    tempnode := node.getFirstChild;
    showmessage('1st child of first node: ' + tempnode.Text);
// "select" the node at pixel position 20, 20
    node := Treeview1.GetNodeAt(20, 20);
    showmessage('node at (20,20): ' + node.Text);

end;
0
 

Author Comment

by:crystyan
ID: 16796390
Thanks!
That`s great!

Could u tell me how could I get the number of Subitems of an Item pls ?
0
 

Author Comment

by:crystyan
ID: 16796392
and the number of the selected subitem/item pls.
0
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.

 
LVL 15

Expert Comment

by:mikelittlewood
ID: 16797224
>> Could u tell me how could I get the number of Subitems of an Item pls ?

If I remember right you just need to use the count funtion of the selected node

TreeView1.Selected.Count
0
 
LVL 15

Assisted Solution

by:mikelittlewood
mikelittlewood earned 120 total points
ID: 16797302
If you want to count ALL items selected throughout the tree you will need to loop and check

var
  i, iCount: Integer;
begin
  iCount := 0;
  for i := 0 to Pred(Treeview1.Items.Count) do
  begin
    if Treeview1.Items[i].Selected then
      Inc(iCount)
  end;
  ShowMessage(IntToStr(iCount))
end;
0
 

Author Comment

by:crystyan
ID: 16798102
I still have a prob ... I have only one item and subitems ... I want when I click on the subitems to show the number of subitem which was clicked ... so if I click on the root don`t wanna happen anything ...

I`ve increased the points so I`m going to split them ...

Thanks
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16801577
procedure TForm1.TreeView1Click(Sender: TObject);
var
    i: integer;
begin
    if treeview1.Selected = nil then label1.caption := ''
    else
    begin
        if treeview1.Selected.Parent = nil then
          label1.caption := 'root node'
        else
          label1.caption := 'you have selected subitem ' + inttostr(treeview1.Selected.Parent.IndexOf(treeview1.Selected));
    end;
end;
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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

839 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