Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delphi TTreeView Reading Nodes/SubNodes

Posted on 2009-04-02
3
Medium Priority
?
1,911 Views
Last Modified: 2013-11-23
I Need some help, I cant find info on this and I could use Assistence.

I have a Treeview that holds User Selectable information.

It Looks Like So

Medicine
      Asprin
      Cough Syrup
      Stool Softener
Drinks                         <---if a user clicks this
      Soda                          <--Then Add this
      Tea                            <--this
      Pop                            <--and this Text to a ListBox

I Need 2 things
If a user Clicks a Level 0 (Medicine, Drinks) Then Read All of the Subnodes from that Node To a ListBox.
If the User Clicks a Level 1 Node (soda, pop, tea, Stool Softener, Ect.), Read the Label of only that Child Node.

It sounds Simple... but I cant seem to get it figured out :( IT was a pain to use a Listview as well.
0
Comment
Question by:jamerslong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Expert Comment

by:btframework
ID: 24055293
let say your trivew called as TreeView1. Then

var
  Node: TTreeNode;
  Child: TTreeNode;
begin
  Node := TreeView1.Selected;
  if Assigned(Node) then
    if Node.HasChildren then begin
      // If it has child nodes then it is Node[0] in your sample
      // Enum its child nodes
      Child = Node.GetFirstChild;
      while Assigned(Child) do begin
         ListBox1.Items.Add(Child.Text);
         Child := Node.GetNextChild(Child);
      end;
   end else
      // We are here if node has no child node so simple add its text
      ListBox1.Items.Add(Node.Text);
0
 
LVL 3

Accepted Solution

by:
btframework earned 2000 total points
ID: 24055322
Forget to say that you have to add this code in OnChange Event.

Like this:

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
  Node: TTreeNode;
  Child: TTreeNode;
begin
  Node := TreeView1.Selected;
  if Assigned(Node) then
    if Node.HasChildren then begin
      // If it has child nodes then it is Node[0] in your sample
      // Enum its child nodes
      Child = Node.GetFirstChild;
      while Assigned(Child) do begin
         ListBox1.Items.Add(Child.Text);
         Child := Node.GetNextChild(Child);
      end;
    end else
      // We are here if node has no child node so simple add its text
      ListBox1.Items.Add(Node.Text);
end;
0
 
LVL 4

Author Closing Comment

by:jamerslong
ID: 31566030
Beautiful, Thanks a bunch....
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

604 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