MS Forms Tree View Slow Loading Issue

@MajP
Thanks for sharing your dataset for testing.

You have made a very educational demo. I don't know how much of the existing code is a part of the tree view examples, but it seems like a challenge to try to evaluate right now. I did make tests with the three versions.
Light recursive load was fast as advertised. It only builds the necessary nodes to begin and that is reasonable. Full recursive load and full non-recursive load were slow, I don't know which one is slower because I did not check the times, but the two froze Access. I was not able to reproduce the crash, though.

Once I get some free time, I will try to load only the initial nodes to see how it performs.
 
One thing I observed is that it seems to slow down almost exponentially with the number of nodes. So 2000 nodes takes much more than double the time it takes to load 1000, and so on. This is another reason why just loading the minimum amount and then as needed is so efficient.
 
Hi,

Sorry for late responding. I checked the demo light load is much faster than full load (big hand for @MajP). However there is a bit of delay when expanding a node in light load that is understandable that it load the nodes. One thing more, there are different number of child nodes on expanding a node for the first time and the second time.

I could not apply it in my project yet because the version of JKP class modules in my project are v26.3 whereas in wrapper demo are v25 (there is no NodeClick event in v26 however there is mCtrl_Click event but code in it is completely different from NodeClick). I am still trying to understand how to get into my project.
 
Last edited:
One thing more, there are different number of child nodes on expanding a node for the first time and the second time.
That is a big problem. There may be something in my logic so I will have to relook and see if I can replicate.

I could not apply it in my project yet because the version of JKP class modules in my project are v26.3 whereas in wrapper demo are v25 (there is no NodeClick event in v26 however there is mCtrl_Click event but code in it is completely different from NodeClick). I am still trying to understand how to get into my project.
This was a big problem with the JKP class IMO. If you look at my demo you will see I added code for 2 additional events. NodeClick and NodeExpanded. I believe I put comments in the JKP class where I made updates. Just search for "MajP" and or "Added".

If you cannot replicate what I did in 26.3 then I will give you an update when I get a chance. I will be busy this week. It is only a few lines of code. I created 2 events and raise them later in the code.
 
That is a big problem. There may be something in my logic so I will have to relook and see if I can replicate.


This was a big problem with the JKP class IMO. If you look at my demo you will see I added code for 2 additional events. NodeClick and NodeExpanded. I believe I put comments in the JKP class where I made updates. Just search for "MajP" and or "Added".

If you cannot replicate what I did in 26.3 then I will give you an update when I get a chance. I will be busy this week. It is only a few lines of code. I created 2 events and raise them later in the code.
Thanks a lot for the help. I'm truly thankful for the help. I'm trying to replicate it in 26.3 will update here if I'm able to understand the code and adapt it. Thanks again for your precious time.
 
That is a big problem. There may be something in my logic so I will have to relook and see if I can replicate.


This was a big problem with the JKP class IMO. If you look at my demo you will see I added code for 2 additional events. NodeClick and NodeExpanded. I believe I put comments in the JKP class where I made updates. Just search for "MajP" and or "Added".

If you cannot replicate what I did in 26.3 then I will give you an update when I get a chance. I will be busy this week. It is only a few lines of code. I created 2 events and raise them later in the code.
Hello @MajP,

Hope you're in good health. I was unable to fix the issue and use light load with jkp treeview. I didn't updated here because I didn't want to take your more time and so started using comctl with light load. But it is a nightmare in case of compatibility. So I came here just to know if you had any chance of looking into the code or making lightload possible with jkp treeview?

Best Regards
 
Not at my computer and cannot remem how far I got. The approach is the same. Load only load the minimum for visibility and as you click you load more but again only the min that need to be visible. The jkp may expose some properties to make this easier. In the active X you have to load one more level to show the expand symbol. With the Jkp you might be able to force that symbol if you know it has children.
 
I believe I figured it out.
I did some debugging in my code and on the first time I expanded I put a debug.print in it and it showed that the Nodes were being created, but not visible.
If you collapsed it and then expanded it no nodes were created but the previously created nodes became visible.
This told me that in the JKP code there has to be some method to show newly created nodes visible.
And there is a Refresh method. I simply had to add Refresh and it appears to work.

Add the Me.TreeView.Refresh before the exit sub.

Code:
Private Sub m_TreeView_NodeExpanded(cnode As clsNode)
  'Flush out any remaining nodes in this expanded level and liteload child level
 'This procedure is associated with a light load. Occurs when you expand the branch
  On Error GoTo errlbl
 
  Dim strCriteria As String
  Dim bk As String
 
  Dim rsTree As DAO.RecordSet
 
  Dim NodeID As String
  Dim NodeText As String
  Dim NodeLevel As String
  Dim NodeImage As String
  Dim CurrentNode As clsNode
 
  'Debug.Print cnode.ChildNodes.Count
   If cnode.ChildNodes.Count > 1 Then Exit Sub ' node has already been expanded
 
  Set rsTree = Me.RecordSet  'not sure this is needed probably just use the me.recordset
  strCriteria = "ParentID = '" & cnode.Key & "'"
 
  rsTree.FindFirst strCriteria
  If rsTree.NoMatch Then
    MsgBox "There is no record with a Parent ID of " & cnode.Key & vbCrLf & strCriteria
  End If
 
  'Loop the children of the returned noded
  Do Until rsTree.NoMatch
   NodeID = rsTree.Fields("NodeID")
   'Debug.Print NodeID & " current in MTVW expand"
   NodeText = rsTree.Fields("NodeText")
   NodeLevel = rsTree.Fields("NodeLevel")
 
   'Not sure what this does if the expanded node child is the current node then you do not want to add it
   'The class can wrap the node expanded event into the expanded branch event
   'But not sure why the tag is not already added
   If cnode.Child.Key = NodeID Then
     cnode.Child.Tag = NodeLevel
     RaiseEvent ExpandedBranch(cnode.Child)
   Else
     'If you are light loaded and drag drop then you will get a duplicated key error
  
     Set CurrentNode = cnode.AddChild(NodeID, NodeText)
     Debug.Print "CurrentNode :" & CurrentNode.Key
     CurrentNode.Tag = NodeLevel
     DoEvents
     'If mLoadImages Then
     '  currentImage = Nz(rsTree.Fields(Image_Name_Field), "")
     '  If currentImage <> "" Then CurrentNode.Image = currentImage
     'End If
     'RaiseEvent ExpandedBranch(CurrentNode)
     bk = rsTree.Bookmark
     Call addLiteBranch(NodeID, CurrentNode)
   End If
   rsTree.Bookmark = bk
   rsTree.FindNext (strCriteria)
  Loop
  Me.TreeView.Refresh
  Exit Sub
errlbl:
  If Not Err.Number = 35602 Then 'this is a duplicate key caused by drag drop and light loaded
    MsgBox Err.Number & " " & Err.Description & " Key: " & NodeID & " In Treeview Expand."
  End If
End Sub

because I didn't want to take your more time
The reason we are here is because we enjoy solving these types of problems and sharing what we know. It is never a bother. OK, there are times it is a bother is when people are expecting you to develop something for them from scratch, they do not want to do any work, and they have not tried anything. You be surprised. Some people come here and ask you to build them a working database and then they criticize any suggestion you make.

You will see a flicker when the nodes refresh. It expands then a flicker and the nodes render.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom