开发者

(RAD Studio) Virtual TreeView: how to initialize all nodes at once?

I just discovered this component and started working with it.

I understand that the whole con开发者_StackOverflow中文版cept 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?


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).


treeview.FullExpand;


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜