Solved

TreeView question: How can i implement this? (need help!!!)

Posted on 2004-08-22
12
527 Views
Last Modified: 2010-04-05

Hi folks,

I have a MS Access that contains a table called CUSTOMERS.
The table CUSTOMERS contains 3 fiels: NAME, DATE and PRODUCTS. The field products store the products that the CUSTOMER bought. Ok. This is my database and my table.

My question is: how i put that information in a TreeView object? More clearly, the TREEVIEW must be similar to:

+ CUSTOMER 1
+ CUSTOMER 2
...

If the guy click on the plus signal of the CUSTOMER 1, the TREEVIEW change to:

+ CUSTOMER 1
- Name
- Date
+ PRODUCTS
+ CUSTOMER 2

If the guy click on the plus signal of the PRODUCTS, the TREEVIEW change to:

+ CUSTOMER 1
- Name
- Date
- PRODUCTS
- PRODUCT 1
- PRODUCT 2
+ CUSTOMER 2


Do you imagine how can i do that? Please, if you know some component, i deeply ask you for dont only put the name, but the example too, because i´ve tried many components and i didnt get work with them.

Thanks very much and best regards.

0
Comment
Question by:joelsilva
  • 6
  • 5
12 Comments
 
LVL 11

Expert Comment

by:calinutz
ID: 11868530
I would not recomend you to do that because it woul slow down your entire application. Especially when you want to populate the treeview. It will be a pain.
  You could do it simple with the TreeView component from delphi, or you could try other (more complicated to use) components... such as VirtualTreeView from
http://www.soft-gems.net/VirtualTreeview/VT.php

I would suggest that you search for another way to present your data.
Cheers.
0
 

Author Comment

by:joelsilva
ID: 11869543
Hi Calinutz, thx for your comments.

As i told, i know many components related to TreeView and I know VIRTUAL TREEVIEW too (it is installed here), but i dont know how implement what i need with that. I´ve already looked forward resources and didnt find. So, do you know how can i do what i need with VIRTUAL TREEVIEW?
0
 
LVL 7

Accepted Solution

by:
DavidBirch2dotCom earned 25 total points
ID: 11869808
To use a virtual tree view you need to do a few things,

first declare a new type for holding data for the nodes asimple example would be

type

  PMyRec = ^TMyRec; // create a pointer for this type - very important
  TMyRec = record
    Caption: WideString; // add any othervaribles here, you probably only need a caption feild
  end;

then you need to set the nodedatasize for the treeview on create add something like
  treeview.NodeDataSize := SizeOf(TMyRec);


To set the caption of the node then use the treeview event OnGetText to set the caption something like

var
  Data: PMyRec;

begin
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    Text := Data.Caption;
end;

you could then set the caption or text depending on which customer it is

To add nodes make a function similar to this

function Addnode(Addtype: integer; Addernode: Pvirtualnode): Pvirtualnode;
Begin
   Addnode:= Addernode;
   with mytree do
   Begin

   Case addtype of
   0: // root
   Begin
      RootnodeCount:= RootnodeCount+1;
      Addnode:= Rootnode.LastChild;
   end;
   1: // child
   begin
      ChildCount[Addernode] := ChildCount[Addernode] + 1;
      Expanded[Addernode] := True;
      InvalidateToBottom(Addernode);
      Addnode:= Addernode.LastChild;
   end;
   2: // sibblin
   Begin
      Addernode:= Addernode.Parent;
      ChildCount[Addernode] := ChildCount[Addernode] + 1;
      Expanded[Addernode] := True;
      InvalidateToBottom(Addernode);
      Addnode:= Addernode.LastChild;
   end;
   end; //case

   end;  //with

end;

To access the data on a node use

var
  Data: PMyRec;

begin
  Data := mytree.GetNodeData(Node);

and then you can access it, I

 hope that that helps

DAvid
0
 

Author Comment

by:joelsilva
ID: 11873023
I dont have Delphi here, but i will test your code tonight... Thx. very much DAVID.
0
 

Author Comment

by:joelsilva
ID: 11875938
Hi David,

I did exactly what you recommended and I got the error here:

==================================================
var
  Data: PMyRec;
begin
  Data := mytree.GetNodeData(Node); //  HERE is the ERROR: NODE was UNDECLARED           ==================================================


I disponibilize the PROJECT that i did (http://www.cordeirorodrigues.com.br/download/01.zip).

As I said, i need take data from my MS Access database and show them in a TreeView. Could you give me a exemple (with any MS Access or Interbase database), using my PROJECT? Could be something very simple, but showing the formation extracted from a database file. I don´t know how implement this using VIRTUAL TREEVIEW.

If you cannot do that, no problem.

Best regards.
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11879535
ok have a look @ this see if this helps you

www.davidbirch2.com/hidden/test.zip

David
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:joelsilva
ID: 11880767
Hey DAVID, you got it!!! Thx. and thx. very much for that.

Just one point: Could you add another NODE for me, pls? So, i think that i will get implement everything that i need.

Something like:

- CUSTOMER := ????
  - Name := ????
  - Date := ????
  - Node 1  // Please, could you put this?
    - Node 1.1  // Please, could you put this?
    - Node 1.2  // Please, could you put this?

- CUSTOMER := ????  // Please, could you put this?
  - Name := ????  // Please, could you put this?
  - Date := ????  // Please, could you put this?
  - Node 1  // Please, could you put this?
    - Node 1.1  // Please, could you put this?
    - Node 1.2  // Please, could you put this?
  - Date := ????
  - Node 1  // Please, could you put this?
    - Node 1.1  // Please, could you put this?
    - Node 1.2  // Please, could you put this?
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11881093
ROLF :) (Rolling On The Floor Laughing) - // Please, could you put this?

right, well thats why I left he  for loop in comments for you, if you can write the loop to get all the records that will deal with making a new node + children for each customer.  I didnt add it as it would depend greatly on how you are using your database...

As for adding

- CUSTOMER := ????
  - Name := ????
  - Date := ????
  - Node 1  // Please, could you put this?
    - Node 1.1  // Please, could you put this?
    - Node 1.2  // Please, could you put this?

you can add additional nodes on the same level as name and date by adding the code

   childnode:= Addnode(1,Parentnode); // add another child
   Data := VirtualStringTree1.GetNodeData(childnode);
   Data.Caption:= ' feild name:= ???'; // data in feild one

to get to the level below that -  try the code

   childnode:= Addnode(1,Parentnode.lastchild); // add another child to the last child of the customer node
   Data := VirtualStringTree1.GetNodeData(childnode);
   Data.Caption:= 'my child:= ???'; // data in feild one

I think that solves the problem?

DAvid
0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11881119
opps we are forgetting to clear the memory, add the following code on the OnFreeNode event

var
  Data: PMyRec;

begin
  Data := Sender.GetNodeData(Node);
  if Assigned(Data) then
    Data.Caption := '';
end;
0
 

Author Comment

by:joelsilva
ID: 11881232
Cool! Now i can improve what i need... Thank you very much man.

Let me see if i perfectly understood:

Where you put "CUSTOMER:= ????" i must add some code there to take information from my database, isn´t? So, maybe will be:

=======================================
CUSTOMER:= ADOQuery1.FieldByName('customer').AsString
=======================================

Am i correct? I mean, i understood perfectly your code. I just want confirm that i could integrate your code with my database.

0
 
LVL 7

Expert Comment

by:DavidBirch2dotCom
ID: 11881301
yeah somthing like that

Data.Caption:= ADOQuery1.FieldByName('customer').AsString;

would do i think

David

0
 

Author Comment

by:joelsilva
ID: 11881327
I deeply thank you very much for your attention and precious comments.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

13 Experts available now in Live!

Get 1:1 Help Now