Solved

# Generate a treeview

Posted on 1999-01-11
172 Views
I have a dataset with fields 'son and 'father'.
(root with father=spaces)(likely subdirectory directory)
Do you know any algorithm generate a tree with
this dataset?
Please tell me. Thanks.
0
Question by:mathematics
• 2

LVL 12

Expert Comment

ID: 1355996
There are some data aware tree views around. Take a look on DSP(http://sunsite.icm.edu.pl/delphi) - there is a search engine.

Cheers,

Raymond.
0

LVL 1

Accepted Solution

apaparis earned 50 total points
ID: 1355997
If Id is primary key
and father is pointing to father record

// Body
DataSet = "Select * from table where father = 0 order by Id"
while not eof begin
appendSubtree(Id)
DataSet.Next
end

Procedure appendSubtree(AnId)
currentTreeNode := <-- append current rec to tree root
SubDataSet := "Select * from Table Where Father = " + IntToStr(AnId)

While Not SubDataSet.Eof Begin
AppendSubTree (Id)
SubDataSet.Next
End
End

0

LVL 27

Expert Comment

ID: 1355998
hi mathematics,

instead teh table i used, you can do it with a dataset also,

procedure TForm1.Button1Click(Sender: TObject);
var
Found : Boolean;
I : Integer;
t : TTreeNode;
begin
{ Clear Treeview }
while treeview1.Items.count > 0 do treeview1.Items[0].delete;
{ Create a root }
table1.open;
table1.first;
while not(Table1.eof) do
begin
i := 0;
Found := False;

{ Search for Father }

while Not(Found) and (i < TreeView1.Items.Count) do
begin
Found := Table1.FieldByName('Father').AsString = Treeview1.Items[i].Text;
if Not(Found) then inc(i);
end;

If Found then  {Father exists, add son }
begin
{ Do Something else with t }
end
else
begin     {Father not exists, add Father to root, add son }
{ Do Something else with t }
{ Do Something else with t }
end;
Table1.Next; {Next Record}
end;
table1.Close;
end;

can be optimized, of course

meikl
0

LVL 1

Expert Comment

ID: 1355999
Sorry. This is right

If Id is primary key
and father is pointing to father record

// Body
DataSet = "Select * from table where father = 0 order by Id"
while not eof begin
currentNode := <-- append current rec to tree root
appendSubtree(Id, CurrentNode)
DataSet.Next
end

Procedure appendSubtree(AnId, ANode)
SubDataSet := "Select * from Table Where Father = " + IntToStr(AnId)

While Not SubDataSet.Eof Begin
SubTreeNode := <-- append current rec under ANode
AppendSubTree (Id, SubTreeNode)
SubDataSet.Next
End
End

0

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

#### 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.

#### Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!