Solved

Treeview Question

Posted on 2001-06-12
7
218 Views
Last Modified: 2010-04-06
This is what I want to do. Have a text file with the following fields.

***Record 1
MyCategory
My Software
File1
File2
http://www.test.com
***

***Record 2
AllCategory
Shareware
File1
File2
http://www.test2.com
***

I want to create a treeview with all the records in the Treeview, but I only want to display the first field in the treeview and the rest of the information in labels.

The parent nodes must be according the categories.
0
Comment
Question by:DigitalNam
[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
7 Comments
 
LVL 2

Expert Comment

by:gikam
ID: 6184763
As I understood, u dont need a tree.
put the first field in la listbox. Create 4 labels for the other 4 fields.
in the lixtbox1.onclick event undate the content of the 4 labels.
ok?
0
 
LVL 8

Accepted Solution

by:
Cesario earned 25 total points
ID: 6185077
Hi DigitalNam,

try this code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
     Procedure AddNewRecord(Category,Software:String; Files:tStrings);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


Procedure Tform1.AddNewRecord(Category,Software:String; Files:tStrings);
VAR
 Node : tTreeNode;
 Cnt  : Integer;
Begin
  Node := TreeView1.Items.AddChild(NIL, Category);
  Node := TreeView1.Items.AddChild(Node, Software);
  For cnt := 0 TO Files.count-1 do
    TreeView1.Items.AddChild(Node,Files.Strings[cnt])
End;

// Hier you open your Text file and insert the records
// in the Treeview

procedure TForm1.Button1Click(Sender: TObject);
VAR
  files : tStrings;
begin
  Files := tStringList.Create;
  Try
    Files.Add ('File1');
    Files.Add ('File2');
    Files.Add ('File3');
    Files.Add ('File4');
    AddNewRecord('A Category','My Software',Files);
  Finally
    Files.Free;
  End;
end;

end.

Best Regards

Cesairo
0
 
LVL 4

Expert Comment

by:Colin_Dawson
ID: 6185430
Look at the TTreeNode.Data property

You can use this to store lot's of information directly within the node.

I'll not go into greate detail about your specific problem but here's a general pointer.


Type
  TCargo = Class( TObject )
    MyTest : String;
  End;


Procedure AddMyNode( TreeView : TTreeView );
Var
  Node : TTreeNode;
Begin
  Node := TreeView.Items.Add( nil, 'My Caption', TCargo.Create );

  TCargo( Node.Data ).MyTest := 'Blah Blah Blah';
End;


procedure TForm1.MyTreeOptionsDeletion(Sender: TObject; Node: TTreeNode);
begin
  If Node.Data <> nil Then
  Begin
    TCargo( Node.Data ).Free;
    Node.Data := nil;
  End;
end;


You can then save whatever you want in the Tree.  Using techniques like Poly-morphism you easily create very complex tree's with different kinds of data on each node!

Regards

Colin Dawson
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:DigitalNam
ID: 6187121
I appreciate all the help, but I still want to load all the items from a text file. The basic idea behind the project is a software CD. Looks something like this

Essential Software
  Winzip
  DirectX
Internet Software
  Napster
  Internet Explorer
Graphics Software
  Corel Draw
  Paint Shop Pro

How can I store for example the Winzip item with a link to where the program is and some general info about the program. Hope this helps.

Thanks again.
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6187168
DigitalNam,

I must go... but i will send you a demo application tomorow
Ok..

Cesario
0
 
LVL 3

Assisted Solution

by:MarcG
MarcG earned 25 total points
ID: 6188890
you could abuse an ini file for storing the informations
the structure would be like this

[Essential Software] //would be a parent node
 Winzip=linktoWinZip //would be a child node
 DirectX=linktoDX    //...
[Internet Software]
and so on


when you read the file you can go from section to section with a parentnode for the items with the sectionname as caption.

So you would creat a node (either with parent nil or a major parent) with the caption 'Essential Software' and create nodes with this node as parent that have 'Winzip' etc. as caption and the rest of the things you want to have there you can store with the node.data.
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 9286064
DigitalNam,
No comment has been added lately (813 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between Cesario http:#6185077 and MarcG http:#6188890

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

DragonSlayer
EE Cleanup Volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

742 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