Table Setup for a Treeview control (1 Viewer)

KeithG

AWF VIP
Local time
Today, 09:10
Joined
Mar 23, 2006
Messages
2,592
I am designing a form with a treeview control and am looking for suggestions on how to setup my tables to store the information for the nodes. The issue is that a child node, can have children. So the Child can actual be a parent. So two tables with a one to many relationship doesn't seem to fit. Any suggestions? my table schema is below.

tblParentNode
NodeID- PK
NodeName


tblChildNode
NodeID - FK/PK
ChldNodeID - PK
ChldNode
 

KeithG

AWF VIP
Local time
Today, 09:10
Joined
Mar 23, 2006
Messages
2,592
What about the below table schema? Thoughts? Comments?


tblParentNode
NodeID - PK
NodeName

tblChildNode
ChldNodeID- PK
ChldName

tblParantChildAssociation
NodeID - PK/FK
ChldNode - PK/FK


This way, if a child node has children I can just add a record to the Parent table also. Any advice is appreciated
 

WayneRyan

AWF VIP
Local time
Today, 17:10
Joined
Nov 19, 2002
Messages
7,122
Keith,

Obviously you can't have a table for each level, so one table to represent the
tree will be sufficient.

tblTree
=======
NodeID - AutoNumber
NodeName
ParentNode - FK to Parent NodeID

That's the way that software like MS Project lay things out. It's basically just
a linked list with the parent at the terminal end.

A Null ParentNode denotes a root.

hth,
Wayne
 

KeithG

AWF VIP
Local time
Today, 09:10
Joined
Mar 23, 2006
Messages
2,592
Thanks Wayne. You sunk the Eight ball on the break there.

I know, its a lame joke but I noticed you were a pool player.
 

Users who are viewing this thread

Top Bottom