Solved

Treeview Question

Posted on 2001-06-12
7
216 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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