Adding Child Nodes to Treeview

A

accessuser1308

I currently have a form with a treeview control for a family tree database I
have made. I have the tree generated from a table. The key for my tree is
WhoID. I can make a tree that links WhoID with a MotherID and a separate
tree that will link the same WhoID with FatherID. I would like to make a
tree that will have the "child" WhoID associated with both MotherID and
FatherID, such that when someone follows the family tree the child is
associated with both "branches" of the family tree. Is this possible to do?
How would it be done? Your help is greatly appreciated.

Thank you
 
G

GB

The fact that you have created at least a branch of the tree to follow either
the mother side or the father side is a step beyond what I have been able to
do in the last 10 minutes. That being said, yes it is possible to make a
tree that has in essence one "parent" node (the child in question) with two
"children" nodes (one for each parent). This is considered a binary tree.

For every node, there are two children (or spaces for them anyways).
Obviously with geneology you will have some "holes" in the data, but that is
part of the "fun" and research.

I am not sure how you have thus far actually "created" the node for the
"child" (parent of the person in question), but you would have to create two
children nodes, and designate one as maternal and one as paternal.

Normally with a binary tree, if you start at level 1 (say yourself) you can
call this node 1. Then the next level will be made up of 2 persons, nodes 2
and 3. The next level will have 4 persons available, nodes 4, 5, 6, and 7.
Next level will have 8 persons, 8 through 15 respectively. If you say always
consider the odd node (after node 1) equal to either maternal or paternal,
then the even node will be the opposite. Haven't really thought through the
importance of that at the moment, but I seem to recall something from some
programming class I took 12 years ago. It has a bit to do with deletion of
nodes, binary tree maintenance (i.e., insertion of a new layer of nodes), and
tree balancing. (You won't be doing any tree balancing in this "project"
because you are always looking for the straight path from where you are to
the next "generation")

You said that you had a table that contained the WhoID and that you can link
the WhoID with either the MotherID or the FatherID. In this case, if you
have a WhoID, you need to pull both the MotherID and the FatherID and place
those respectively (even or odd of the "Parent" node for the child of the
mother and father). Yes, it can get a little confusing thinking about child
nodes as being the parents of the person.

Once the child node has been established, the same fill in would be needed
for that individual. I seem to recall now that knowing the level of the tree
and the current node number helps to store the next group. For example, with
node 1, which is the first level the bottom or left part of the tree is node
2, this is the current node * 2. The Right or top is 1*2+1. From here to go
left (or down) you take the current node *2 or to go right you take the
current node *2+1. To go back to the parent node (or child of the
human/animal parent) if the number is even, then divide by 2, if the number
is odd then subtract 1 and then divide by two.

So one way to work through the tree, is to 1) keep track of the highest
valued node that is currently on "file" and ensure that sufficient room is
available in the tree to add the next layer. 2) starting at node 1, insert
the information for nodes 2 and 3. Move to Node 2 and insert the information
for nodes 4 and 5. Move to Node 3 and insert the information (if any) for
nodes 6 and 7. Move to Node 4 and insert the information for nodes 8 and 9,
node 5 nodes 10 and 11, node 6, etc.... continue this process until there is
no information available for any node that is a child of the last node of the
last level.

Now, if you have to perform tree "memory" management, then you have to
basically increase the size of your binary tree to twice it's previous size
if you are up to a node that is half of the existing size and there is data
still to be processed.

My guess... Is that you currently have a tree that is one branch, where node
1 is the person in question, node 2 is say the mother of that child, node 3
is the mother of that child (grandmother), node 4 is the mother of that child
(great-grandmother), etc.. What you would need to do is use the above "math"
to actually assign the mother to say the even values 2, 4, 8 (to get the same
great-grandmother to child relationship) and the fathers to the odd numbers
(5, 9) to get the husband of that same great-grandmother.

Again at each step identify if there exists a real life parent (data for it
anyways), and then (if memory management is performed by the programmer not
just by the control) test to see if multiplying the current node by 2 is
within the bounds of the lower and upper nodecount, if it is not then double
the size of the tree to permit insertion of the new "child" node.

Confusing enough for you? Really, take a look at binary tree data
structures since you are working with the possibility of only two parents
("child" nodes) from each node.
 
G

GB

For assistance, you can determine if the current node number is odd (or even)
by evaluating the result of the current node mod 2. For example, if the
current node is 7, then 7 mod 2 is equal to 1.

(One way to think about how the mod function works is to take the first
value, 7, and subtract the second value, 2, until the final result is greater
than or equal to zero and less than the second value. The whole number left
over from this process is provided back as the result.)

So 6 mod 2 is like 6-2=4-2=2-2=0 therefore it returns 0.

So to get to the "parent" node (child of human/animal parent) you would use
something like:

If currentNode.location mod 2 = 1 then
reassign currentNode = (CurrentNode.location-1)/2
else
reassign currentNode = (CurrentNode.location/2)
end if

Not knowing how to work specifically with the treeclass control, I don't
have the coding to "reassign currentNode". It may be as simple as currentNode
= ...

As for CurrentNode.location, that too is my way of presenting the value
assigned to the node location without knowing the details of the treeclass
control. I would think that somehow there is a numeric representation
associated with each node, it is more of a question of how to "obtain" that
information or keep track of it that becomes the issue. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Add Child Node to Treeview 5
treeview question 3
Family Tree Chart 10
Rebuilding Treeview 1
looping through nodes 0
Treeview rebuild 1
Add nodes to tree view control 0
Treeview Properties 4

Top