3

I just discovered this component and started working with it.

I understand that the whole concept of it is to initialize nodes on the go as they are needed but I need all of them to initialize instantly.

What is the smart way to do it?

The only thing I came up with is to use GetLast() after adding nodes.
I believe, there is a better way, or not?

Johan
  • 74,508
  • 24
  • 191
  • 319
Andrew
  • 2,309
  • 4
  • 27
  • 42
  • Can you explain "why" you need all nodes be initialized instantly? In this case the Virtual TreeView looses much of its speed and "virtuality". – Uwe Raabe Apr 12 '10 at 05:51
  • Because it is a bad design and I do not have an option to change software design and make it virtual :( – Andrew Apr 12 '10 at 06:01
  • 2
    The "smart way" is to **not do that**. – Rob Kennedy Apr 12 '10 at 07:01
  • 2
    Well, if you are working with databases the virtual paradigm must be violated. Otherwise you get unexpected results when accessing nodes "on demand". – Wodzu Apr 12 '10 at 07:55
  • @Wodzu: does it mean that I should go for another component or simply compromise "virtuality"? – Andrew Apr 12 '10 at 08:49
  • @Andrew, No apart from that what I've mentioned VritualTree is great. I am using it in my commercial projects in conjunction with databases and it works without any problems. – Wodzu Apr 12 '10 at 09:56

3 Answers3

7

The more correct way to initialize a single node instantly, is to use the ValidateNode method, instead of already suggested FullExpand. According to the VT's documantation:

procedure ValidateNode(Node: PVirtualNode; Recursive: Boolean);

TBaseVirtualTree.ValidateNode Method

ValidateNode ensures that the given node (and all its children, if Recursive is true) are initialized. If Node is nil then the hidden root node is used (which makes only sense if Recursive is true, in which case the entire tree is validated).

IvanP
  • 91
  • 1
  • 1
  • 2
    This should have been the accepted answer, since FullExpand will change **visually** expand the entire tree which you might don't want it to happen. – Edwin Yip Feb 04 '18 at 16:28
4

You can write your own procedure to build treeview manually.

Example:

procedure TForm1.BuildTree;
var
  i: integer;
  Data: ^TYourRecord;
  pNode, cNode: PVirtualNode;
begin
  for i:=0 to 1000 - 1 do
  begin
    //build parent node
    pNode := VT.AddChild(nil);
    Data := VT.GetNodeData(pNode);
    //fill record values
    Data.SomeVar := 'Parent Node';
    //build child node
    cNode := VT.AddChild(pNode);
    Data := VT.GetNodeData(cNode);
    Data.SomeVar := 'Child Node';
  end;
end;
Linas
  • 5,485
  • 1
  • 25
  • 35
3

treeview.FullExpand;

Attila Szasz
  • 3,033
  • 3
  • 25
  • 39