I'm working with a TListView
which has drag/drop capabilities to drag one or multiple items into one other item, as a form of merging. When you drag an item to the top or bottom of the control, I need it to automatically scroll up or down but it doesn't. The same applies for scrolling right or left in certain view styles. How can I make it automatically scroll in the direction the user's dragging the item?
PS: I have VCL Themes enabled as well
A ListView in Android is a scrollable list used to display items.
For instance I want to scroll automatically to some Container in the ListView if I press a specific button. ListView(children: <Widget>[ Container(...), Container(...), #scroll for example to this container Container(...) ]); flutter. listview.
ListView itself is scrollable.
Did not test much, but the below try enables a timer when an item is dragged outside the control over its parent (in the case of the example, the form), and the timer event tests the cursor position to find out if a scroll message should be send to the listview.
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled := False;
Timer1.Interval := 500;
end;
procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if Source = ListView1 then
Timer1.Enabled := True
else
Timer1.Enabled := False;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
Pt: TPoint;
begin
// Stop timer and exit if not dragging any more
if not ListView1.Dragging then begin
Timer1.Enabled := False;
Exit;
end;
Pt := ListView1.ScreenToClient(Mouse.CursorPos);
if Pt.Y < 0 then
ListView1.Perform(WM_VSCROLL, SB_LINEUP, 0)
else
if Pt.Y > ListView1.ClientHeight then
ListView1.Perform(WM_VSCROLL, SB_LINEDOWN, 0)
else
Timer1.Enabled := False;
end;
procedure TForm1.FormDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
Timer1.Enabled := False;
end;
If it works Ok, you can incorporate horizontal scrolling too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With