delphivirtualtreeview

How to Auto Update the CheckState of the parent nodes When Child's Changed Programmingly?


I am using Delphi XE3 with Virtual TreeView.

I have enabled the toAutoTristateTracking option.

WHen I try to change the check state of a node manually, then the affected node's checkstate will change as well.

However, when I do the same thing programmingly, for example

PNode^.CheckState := csMixedNormal;

or

PNode^.CheckState := csCheckedNormal;

Only PNode check state will be changed. The affected nodes will not change their states. Why?


Solution

  • Don't access CheckState of a node directly. Use array property CheckState[Node: PVirtualNode] of TBaseVirtualTree to read/write check state. Setting check state via the property will apply functionality related to tick boxes as well as fire appropriate events like OnChecking, OnChecked, OnInitNode, ...

    This is what you should do instead:

    VirtualStringTree1.CheckState[PNode] := csCheckedNormal;