Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get User Selected Node on TreeView

2,048 views
Skip to first unread message

Jay Jackson

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
Hello,

How do I get the node (index or text) from a Treeview node when the user
clicks on the item? OnChange fires whenever the tree is changed, like when
its created.

Thanks

Andrea Petrelli

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
Call the method treeview.items.beginupdate,
create the nodes,
call the method treeview.items.endupdate.
When the items is updating (after call of beginupdate) delphi don't call
onchange.

Excuse for my english.
Andrea

Jay Jackson <jjac...@ndcorp.net> wrote in message
8ls9fl$7v...@bornews.borland.com...

Jay Jackson

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
How do I get the selected index?

Andrea Petrelli <petrell...@ctech.it> wrote in message
news:3981ae45_2@dnews...

Andrea Petrelli

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
in the onchange event there is a variable called "node" that is the current
selected node.
bye

Jay Jackson <jjac...@ndcorp.net> wrote in message

8lsatf$7v...@bornews.borland.com...

MrBaseball34

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
Gees, man, can't you read the help file to know that
the TTreeNode has a SelectedIndex property?


Jay Jackson <jjac...@ndcorp.net> wrote in message

news:8ls9fl$7v...@bornews.borland.com...

Andrea Petrelli

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
do you read the first message of this thread?

"How do I get the node (index or text) from a Treeview node when the user
clicks on the item? "
with the selectedindex property you can get the currently selected node, but
jay jackson would to konw this when the user click on items.
bye


MrBaseball34 <mrbase...@hotmail.com> wrote in message
8lsbn8$7v...@bornews.borland.com...

Jay Jackson

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
No, I cannot read the help file because it is not installed on my laptop. I
did attempt to use code insight, but none of these work they way I need them
to.

if treent1.selected = 1 then // not valid
if treent1.selectedindex = 1 then // not valid
if treent1.selected.SelectedIndex = 1 then // valid, but returns index of
imagelist - not selected item.

This works

if treent1.selected.text = 'Item One'

but I would rather get the index number so I can use a case statement.

PS. MrBaseball - in the time it took you to write that silly response, you
could of simply answered the question with specific code. At least if your
gonna be a smart-ass - post an accurate response.


MrBaseball34

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
I will admit that even I was wrong in assuming that SelectedIndex
was the correct property. It is AbsoluteIndex as shown in the snippet
below...You need to use the OnChange or OnChanging methods.

procedure TForm1.TreeView1Changing(Sender: TObject; Node: TTreeNode;
var AllowChange: Boolean);
begin
ShowMessage(IntToStr(Node.AbsoluteIndex));
end;

OR

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
ShowMessage(IntToStr(Node.AbsoluteIndex));
end;

I'd suggest you install the help files, anyway...

Jay Jackson

unread,
Jul 28, 2000, 3:00:00 AM7/28/00
to
Thank you sir, that worked just fine.

Marc Scheuner

unread,
Jul 31, 2000, 3:00:00 AM7/31/00
to
On Fri, 28 Jul 2000 11:53:36 -0400, "Jay Jackson"
<jjac...@ndcorp.net> wrote:

>How do I get the node (index or text) from a Treeview node when the user
>clicks on the item? OnChange fires whenever the tree is changed, like when
>its created.

.... or when the user clicks on a different node! Use that OnChange
event and check the Node parameter being passed into it.

Otherwise, the TTreeView.Selected returns the TTreeNode that's
currently selected. Use it's Index (for position relative to parent),
AbsoluteIndex (position in tree) or Text properties. (for the text
you're looking for)

------------------------------------------------------------------------
Marc Scheuner Software Engineer
FastLane Technologies Inc. Halifax, Nova Scotia, Canada
Email: mailto:msch...@fastlane.com

Plan, Deploy, Manage Windows 2000 with FastLane DM/Suite.
Optimize Windows 2000 now!
http://www.fastlane.com

0 new messages