TreeviewForm imperfection, or by design?

tvanstiphout

Well-known member
Local time
Yesterday, 19:25
Joined
Jan 22, 2016
Messages
686
I downloaded @MajP excellent treeview example from here.
I run frmDemo, select "Show Checks", and check the box for Dr. Andrew Fuller. I answer Yes to check the descendants, and then expand the node to see the result (see screenshot).
Not all descendants are checked. I believe this is a side-effect of LoadType argument of Initialize method being set to lt_lightload by default.
Maybe it would be better to call expandChildren at the top of CheckDescendants.
1771966002409.png
 
I believe this is a side-effect of LoadType argument of Initialize method being set to lt_lightload by default
That would do it because in the light load not all the descendants are loaded. Only enough to show the expander icons. So that is just offspring for that visible level.
I could write additional code to check and overcome this condition. It would first expand all levels below the selected node.
If your tree is less than 5k nodes you can probably do a full load without a big performance issue.

However, I may need to look at that example because even with a light load the visible nodes should be checked.
 
I looked at the example and it is acting as expected. It needs a line of code to make it work. If you need this solution then you can simply do a full load and it will work. If you need a solution that allows you to do a light load but still mark all descendants then simply modify the code to expand the branch first.

Code:
Private Sub tvw_TreeviewNodeCheck(CheckedNode As Node, Checked As Boolean)
  MsgBox CheckedNode.Text & " is checked: " & Checked
  CheckedNode.Selected = True
  Dim rtn As Long
  If CheckedNode.Checked Then
    rtn = MsgBox("Do you want to check the descendants of " & CheckedNode.Text, vbYesNo, "Checks")
    If rtn = vbYes Then
     
     'add the next line of code to expand the branch first
      TVW.ExpandBranch
      TVW.CheckDescendants CheckedNode
    End If
  Else
    rtn = MsgBox("Do you want to uncheck the descendants of " & CheckedNode.Text, vbYesNo, "UnCheck")
    If rtn = vbYes Then TVW.CheckDescendantsFalse CheckedNode
  End If
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom