Re: Add Child Node to Treeview



You cannot use the same value for strKey for multiple nodes. You'll need to
generate different values, even though they refer to the same child.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"accessuser1308" <accessuser1308@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:FB0B9D11-A598-4A4C-88A4-75AB0BE1422B@xxxxxxxxxxxxxxxx
Thank you for your reply. I had actually tried this approach. My problem
is
the query will now have multiple copies of WhoID, based on the number of
parents in the associated table. When I base the tree on this query I get
an
error that the index is out of range. The code I am using is below:

'Fill Tree
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strKey As String

Set db = CurrentDb
Set rs = db.OpenRecordset( _
"SELECT * " & _
"FROM qryFamTree " & _
"ORDER BY qryFamTree.BDate, qryFamTree.WhoID", dbOpenSnapshot,
dbReadOnly Or dbForwardOnly)
TreeView0.Nodes.Clear

With rs
'Loop through all FamTree-items, adding them to the treeview
While Not .EOF
'Assemble a key for this node, consisting of three arguments
'ndObjectType and ndObjectName will allow me to open a picture or document
when node is clicked - this works fine
strKey = !WhoID & ";" & Nz(!ndObjectType) & ";" &
Nz(!ndObjectName)

If !Parent > 0 Then
'This node is a child-node of some other node;
'Find the parent node and add it below that node's last child
TreeView0.Nodes.Add(getNodeIndex(!Parent), tvwChild, strKey,
!Last & !Suff & ", " & !First & " m. " & !SpouseName).ForeColor = 16711680
', CStr(!ndImage)
Else
'There is no parent - add this node to the treeview's root
TreeView0.Nodes.Add , tvwLast, strKey, !Last & !Suff & ", " &
!First & " m. " & !SpouseName ', CStr(!ndImage)
End If

.MoveNext
Wend
End With
'Clean up
Set rs = Nothing
Set db = Nothing
End Sub
'*************************************************************
Private Function getNodeIndex(ByVal strKey As String) As Integer
Dim intCounter As Integer

'Assume failure (return root)
getNodeIndex = 0

For intCounter = 1 To TreeView0.Nodes.Count
'The key being looked for is the first argument
If Split(TreeView0.Nodes(intCounter).Key, ";")(0) = strKey Then
'Found the node
getNodeIndex = intCounter
Exit For
End If
Next intCounter
End Function


qryFamTree has my main table joined to a second table by WhoID. The
second
table consists of the parent IDs for each parent the person in the main
table
may have. In the query (if the individual had 4 parents) there would be 4
entries for the individual, each one with a different parentID. The form
code errors out when it tries to place the child with a second parent in
the
tree.

Thank you for any suggestions


"S.Clark" wrote:

Thinking while typing...

I would have tables structured as the following:

tblPerson
----------
PersonID
PersonLName
PersonFName
etc...

tblRelations
-----------
PersonID
ParentID (Reference to PersonID)
RelationTypeID

tlkpRelationType
-----------------
RelationTypeID
RelationTypeName

This allows for a person to have multiple parental units (e.g. I had 4),
and
you can specify the relationship type via the RelationTypeID. (Son,
Daughter,
Step-xxx, Foster, Adopted, Ferrel, etc) You can add the RelationTypeName
to
the Node if you'd like.

Then query appropriately to generate the tree nodes.

"accessuser1308" wrote:

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


.



Relevant Pages

  • Re: How to populate a treeview from a dataset
    ... If it is then check to see if the parentId and child id of the ... 15 is a parent and a child of itself. ... And that same business is the headquarters for the purchasing group. ... 15 Null - root tree node, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to populate a treeview from a dataset
    ... If it is then check to see if the parentId and child id of the ... 15 is a parent and a child of itself. ... And that same business is the headquarters for the purchasing group. ... 15 Null - root tree node, ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Add Child Node to Treeview
    ... thinking yesterday afternoon that perhaps one way to get a unique strKey is ... into the!Parent section. ... 'Fill Tree ... qryFamTree has my main table joined to a second table by WhoID. ...
    (microsoft.public.access.formscoding)
  • RE: [PATCH E 11/14] OMAP clock: track child clocks
    ... then disable the child, we will again walk up the tree, but since ... it will be a different clock tree. ... If we add in the parent handling, ...
    (Linux-Kernel)
  • RE: Adding Child Nodes to Treeview
    ... you can determine if the current node number is odd ... So to get to the "parent" node (child of human/animal parent) you would use ... This is considered a binary tree. ...
    (microsoft.public.access.modulesdaovba)

Loading