【问题标题】:Infinite scrolling VirtualTreeView无限滚动 VirtualTreeView
【发布时间】:2015-09-03 13:55:41
【问题描述】:

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

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

【问题讨论】:

  • 您是否只想在用户向下滚动时增加节点数(保持垂直滚动条可见)?或者你想要一个无滚动条的grid,它只记住偏移量并显示刚刚获取的小块(没有垂直滚动条)?
  • 我希望保持滚动条可见,例如sitepoint.com/demos/infinite-scrolling-demo4
  • 如果您有一种快速确定记录数的方法,您可以使用它来设置节点数。您不需要立即加载 data;您可以使用OnInitNode 事件在需要时延迟加载记录。
  • 当控件被调整大小(因此它的垂直滚动条消失)时,这个特性应该如何表现?
  • 这对我个人来说不是一个大问题,因为我的控件无法调整大小。

标签: delphi infinite-scroll vcl virtualtreeview


【解决方案1】:

您可以通过这种方式处理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;

【讨论】:

  • 在 OnResize 回调中,可以调用与 OnScroll 中相同的逻辑(不包括 DeltaY 检查)。这样做的好处是支持在调整表单大小时加载。
猜你喜欢
  • 1970-01-01
  • 2013-03-09
  • 2017-06-24
  • 2012-10-03
  • 2020-12-05
  • 2015-09-07
  • 2012-05-11
  • 2017-01-25
  • 2011-03-26
相关资源
最近更新 更多