TreeView Wackiness

D

David C. Holley

I have a TreeView control which lists out Invoices when the TreeView is
first loaded as in...

Invoice #1
Invoice #45
Invoice #75

Awhile back I needed to clean up the overall form, so I converted the
various command buttons to child 'action' nodes that I place under the
Invoice node when the Invoice is clicked (via the _NodeClick event). the
sub AddActionNodes() creates the nodes when the first Invoice is
clicked. (MoveActionNodes() changes the .Parent property of the action
nodes to move them.)
So when you click on Invoice #45 the nodes are added and the TreeView
becomes via AddActionNodes()

Invoice #1
Invoice #45
Create Reservation
Email Confirmation
Print Purchase Orders
Invoice #75

When another Invoice node is clicked, the child 'action' nodes are moved
to the Invoice node by changing the .Parent property of each of the
nodes via MoveActionNodes()

[Code that loops through the Nodes collection deleted]
Set node.Parent = newParentNode

All of that works like a charm, *BUT* when MoveActionNodes() is first
called (eg on the SECOND time an Invoice node is clicked), the child
'action' nodes are placed under the new Invoice node in descending order
as in

Print Purchase Orders
Email Confirmation
Create Reservation

For each subsequent time that MoveActionNodes() runs the nodes are moved
in the same descending order to the new Invoice.

*Why?*

(As a temp fix, I changed AddActionNodes to add the nodes in descending
order and then did a sort)
 
A

Alex Dybenko

Hi David,
can not say why this happen until I see your code <g>
but I think you can just delete action nodes and then use same proc to add
them to new invoice node - perhaps this could be the easiest solution
 
D

David C. Holley

I did that originally. However, given that I pref to have my code as
generic as possible, I ended up looping through the collection, grabbing
the KEYs to be delted, storing them in an Array and then using the Array
to delete them and then recreate them. I then shifted to looping through
the Array and simply changing the parent property. Of course I just
realized that I could further streamline it by using the
glb_dblActionNodesParent value to target them instead of looping through
all of the NODES. Thanks for the help.

Private Sub addActionNodes(frmName As Form, strTargetNode)
'Child SUB to createActionNodes
'No fracking (BSG reference) idea as to why but in order to have
the moveActionNodes() SUB put the NODES in A-Z order
'when it moves them, this SUB needs to add them Z-A and then do a
SORT. Basically moveActionNodes()
'takes the original group of NODES and puts them in opposite order
when they are first moved

Set actionNode = frmName.ExplorerPane.Nodes.Add(strTargetNode,
tvwChild, , "Print Purchase Order(s)", "print")
actionNode.Key = "06ACT:printPurchaseOrder"
actionNode.Tag = "actionNode"

Call createInvoicePurchaseOrderNodes(frmName, actionNode.Key,
actionNode.Parent.Key)
actionNode.Expanded = True

Set actionNode = frmName.ExplorerPane.Nodes.Add(strTargetNode,
tvwChild, , "Print Invoice", "print") '
actionNode.Key = "06ACT:printInvoice"
actionNode.Tag = "actionNode"

Set actionNode = frmName.ExplorerPane.Nodes.Add(strTargetNode,
tvwChild, , "Print Confirmation", "print")
actionNode.Key = "06ACT:printConfirmation"
actionNode.Tag = "actionNode"

Set actionNode = frmName.ExplorerPane.Nodes.Add(strTargetNode,
tvwChild, , "Email Invoice", "sendEmail")
actionNode.Key = "06ACT:EmailInvoice"
actionNode.Tag = "actionNode"

Set actionNode = frmName.ExplorerPane.Nodes.Add(strTargetNode,
tvwChild, , "Email Confirmation", "sendEmail")
actionNode.Key = "06ACT:EmailConfirmation"
actionNode.Tag = "actionNode"

Set actionNode = frmName.ExplorerPane.Nodes.Add(strTargetNode,
tvwChild, , "Create Reservation", "reservations")
actionNode.Key = "06ACT:CreateReservation"
actionNode.Tag = "actionNode"

Set actionNode = frmName.ExplorerPane.Nodes.Add(strTargetNode,
tvwChild, , "Coded Remarks & Comments", "codedRemarks")
actionNode.Key = "06ACT:CodedRemarks"
actionNode.Tag = "actionNode"

Set actionNode = frmName.ExplorerPane.Nodes.Add(strTargetNode,
tvwChild, , "Batch Reservation Entry", "reservations")
actionNode.Key = "06ACT:BatchReservationEntry"
actionNode.Tag = "actionNode"

Set targetInvoice = frmName.ExplorerPane.Nodes(strTargetNode)
targetInvoice.Expanded = True
targetInvoice.Sorted = True

glb_flgActionNodesExist = True
glb_dblActionNodesParent = getTreeViewKeyValue(strTargetNode)

End Sub
Private Sub moveActionNodes(frmName As Form, ByRef strTargetNode)

Select Case frmName.Name
Case "frmInvoicing" ' Bit ugly just have to be certain that the
control isn't renamed
Set tvTargetControl =
Forms(frmName.Name).Controls("ExplorerPane")
End Select

DoCmd.Echo False
If (tvTargetControl Is Nothing = False) Then
Set newParentNode = tvTargetControl.SelectedItem
For Each node In tvTargetControl.Nodes
Debug.Print node.Key
If node.Key Like "06ACT:" & "*" Then
Set node.Parent = newParentNode
End If
Next node
End If
DoCmd.Echo True

End Sub
 
A

Alex Dybenko

Hi David,
i think the easiest approach is to sort parent node at the end of this code:
If (tvTargetControl Is Nothing = False) Then
Set newParentNode = tvTargetControl.SelectedItem
For Each node In tvTargetControl.Nodes
Debug.Print node.Key
If node.Key Like "06ACT:" & "*" Then
Set node.Parent = newParentNode
End If
Next node
End If

newParentNode.Sorted=true

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
D

David C. Holley

You missed what's happinging.

When moveActionNodes() runs, the nodes are moved to the new parent, but
in the EXACT opposite order that they were added via addActionNodes()
regardless of wether or not I execute .Sorted.

If addActionNodes() adds the following nodes in this order...

Create Reservation
Email Confirmation
Print Confirmation

And .Sorted executed or NOT executed

moveActionNodes() moves the nodes but will place them in this order

Print Confirmation
Email Confirmation
Create Reservation

The workaround that I implemented was to addActionNodes() in this order...

Print Confirmation
Email Confirmation
Create Reservation

Which makes moveActionNodes() move them and place them in the correct order.
 

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

Top