Search code examples
delphinodesvirtualtreeview

Set node state in a virtual tree


I have created a virtual tree with multiple node and I want to disable some of them. I've seen there's a States property of a node. Which is a property of a type TVirtualNodeStates so I've check what kind of states I can set and apparently TVirtualNodeStates is a set of TVirtualNodeState.

TVirtualNodeState can be set to vsDisabled so I guess this is what i need to disable a node in my virtual tree.

But I can't do that. This is what I actually tried:

lNode := myTree.addChild(nil);
lNode.States := vsDisabled;

And it gives me the error

incompatible types between TVirtualNodeStates and TVirtualNodeState

How can I disable a node then?


Solution

  • You could write Node.States := [vsDisabled];, to make your code compilable. But this is not what you are supposed to do. There are node states that you must keep untouched and by the mentioned statement you would throw them away and set only the vsDisabled one. You wanted to write either:

    Include(Node.States, vsDisabled);
    

    or:

    Node.States := Node.States + [vsDisabled];
    

    Another option (that should be preferred) is setting the state by the IsDisabled property:

    VirtualTree.IsDisabled[Node] := True;