Solved

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

Posted on 2004-08-22
12
534 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
[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
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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
 

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

Technology Partners: 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!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month6 days, 4 hours left to enroll

627 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