bdn.borland.com

Article #29996: Enabling automatic scrolling in a TTreeview

Problem:


How do I emulate the scrolling behavior of Windows Explorer when dragging a folder to the top or bottom of my TTreeView?


Answer:


Set your TTreeView's DragMode property to dmAutomatic and then place this code in your Treeview's OnDragOver event:


procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
var
HitTests : THitTests;
begin
HitTests := TreeView1.GetHitTestInfoAt(X,Y);
if (htAbove in HitTests) then
TreeView1.TopItem := TreeView1.TopItem.GetPrevVisible
else if (htBelow in HitTests) then
TreeView1.TopItem := TreeView1.TopItem.GetNextVisible;
end;

Last Modified: 28-MAY-03