Solved

Treeview Question

Posted on 2001-06-12
7
214 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
Delphi component that can load a DLL in design time? 8 53
Help on project with Soap 10 48
CheckListBox usage 3 51
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now