Original Post
🔒 Locked
Tree
Advertisement
Is your data heirarchal? If so, you'll need containers (that would be represented by the nodes on the tree) and data elements, that would be represented outside the tree... as in a ListView pane. (I don't work with VB much, so no specific code for you... sorry)
Or, are you doing something different than a Windows Explorer like app?
Or, are you doing something different than a Windows Explorer like app?
The standard way to store a tree in a relational table is simply to have a self reference, storing the primary key of the parent element ...
Say your table would look like this:
int Id
string Name
... other data ...
just add a column of the same type as the primary key
int ParentId
now of course, you will have to write a recursive (or iterative using stack of course) algorithm to generate a view of the tree, but this is not very hard. I have written just such an algortihm for a coworker in both C# and PHP in just the last 2 weeks.
And simply queries like: WHERE (ParentId = @CurrentId) - will give you all the children of a given node. WHERE (ParentId = NULL) will give you the root element(s).
some other single level operations are very easy too ... it's just the multilevel ops that need looping / recursion.
Say your table would look like this:
int Id
string Name
... other data ...
just add a column of the same type as the primary key
int ParentId
now of course, you will have to write a recursive (or iterative using stack of course) algorithm to generate a view of the tree, but this is not very hard. I have written just such an algortihm for a coworker in both C# and PHP in just the last 2 weeks.
And simply queries like: WHERE (ParentId = @CurrentId) - will give you all the children of a given node. WHERE (ParentId = NULL) will give you the root element(s).
some other single level operations are very easy too ... it's just the multilevel ops that need looping / recursion.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement