Solved

Treeview Question

Posted on 2001-06-12
7
219 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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