有没有办法使用virtualtreeview实现无限滚动?
我想一次加载一定数量的数据库记录,并在用户向下滚动时将它们添加到virtualtreeview。但我不确定如何触发添加新行。
答案 0 :(得分:2)
您可以处理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;