无限滚动VirtualTreeView



是否有办法实现无限滚动使用virtualtreeview?

我想一次加载一组数据库记录,并在用户向下滚动时将它们添加到virtualtreeview。但是我不确定如何触发添加新行。

你可以这样处理OnScroll事件并检查滚动条是否到达结束:

type
  // this interposer class is used to publish the RangeY property
  TVirtualStringTree = class(VirtualTrees.TVirtualStringTree)
  public
    property RangeY;
  end;
procedure TForm1.VirtualStringTreeScroll(Sender: TBaseVirtualTree; DeltaX,
  DeltaY: Integer);
var
  Tree: TVirtualStringTree;
begin
  // if the vertical scroll occurred, then...
  if DeltaY <> 0 then
  begin
    // just a helper variable
    Tree := TVirtualStringTree(Sender);
    // if the client height without the top offset equals, or exceeds (actually, it should
    // never exceed; just for sure) the virtual tree height, then we reached the bottom of
    // the tree, so...
    if Tree.ClientHeight - Tree.OffsetY >= Integer(Tree.RangeY) then
    begin
      // the scrollbar reached the end of the tree; now fetch your data and add some nodes
      // (ideally as a thread task showing some fancy animation; the following is just for
      // example)
      ShowMessage('Fetch your data...');
      Tree.RootNodeCount := Tree.RootNodeCount + 50;
    end;
  end;
end;

相关内容

  • 没有找到相关文章

最新更新