Solved

Treeview Question

Posted on 2001-06-12
7
213 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

11 Experts available now in Live!

Get 1:1 Help Now