Board index » delphi » Get User Selected Node on TreeView

Get User Selected Node on TreeView

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

 

Re:Get User Selected Node on TreeView


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

Quote
Jay Jackson <jjack...@ndcorp.net> wrote in message

8ls9fl$7...@bornews.borland.com...
Quote
> 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

Re:Get User Selected Node on TreeView


How do I get the selected index?

Quote
Andrea Petrelli <petrelli.and...@ctech.it> wrote in message

news:3981ae45_2@dnews...
Quote
> 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 <jjack...@ndcorp.net> wrote in message
> 8ls9fl$7...@bornews.borland.com...
> > 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

Re:Get User Selected Node on TreeView


in the onchange event there is a variable called "node" that is the current
selected node.
bye

Quote
Jay Jackson <jjack...@ndcorp.net> wrote in message

8lsatf$7v...@bornews.borland.com...
Quote
> How do I get the selected index?

> Andrea Petrelli <petrelli.and...@ctech.it> wrote in message
> news:3981ae45_2@dnews...
> > 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 <jjack...@ndcorp.net> wrote in message
> > 8ls9fl$7...@bornews.borland.com...
> > > 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

Re:Get User Selected Node on TreeView


Gees, man, can't you read the help file to know that
the TTreeNode has a SelectedIndex property?

Quote
Jay Jackson <jjack...@ndcorp.net> wrote in message

news:8ls9fl$7v35@bornews.borland.com...
Quote
> 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

Re:Get User Selected Node on TreeView


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

Quote
MrBaseball34 <mrbasebal...@hotmail.com> wrote in message

8lsbn8$7...@bornews.borland.com...
Quote
> Gees, man, can't you read the help file to know that
> the TTreeNode has a SelectedIndex property?

> Jay Jackson <jjack...@ndcorp.net> wrote in message
> news:8ls9fl$7v35@bornews.borland.com...
> > 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

Re:Get User Selected Node on TreeView


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.

Re:Get User Selected Node on TreeView


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...

Quote
> 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.

Re:Get User Selected Node on TreeView


Thank you sir, that worked just fine.

Re:Get User Selected Node on TreeView


On Fri, 28 Jul 2000 11:53:36 -0400, "Jay Jackson"

Quote
<jjack...@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:mscheu...@fastlane.com

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

Other Threads