VirtualTreeView Infinite Scrolling

Is there a way to implement infinite scrolling with virtualtreeview?

I would like to load a certain number of database records at a time and add them to virtualtreeview when the user scrolls down. But I'm not sure how I will start adding new lines.

+4
source share
1 answer

You can handle the event OnScrolland check if the scrollbar has ended like this:

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;
+2
source

Source: https://habr.com/ru/post/1605748/


All Articles