Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make list view scroll while dragging an item up or down?

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

like image 621
Jerry Dodge Avatar asked Sep 16 '12 23:09

Jerry Dodge


People also ask

Does Listview have scroll?

A ListView in Android is a scrollable list used to display items.

How do I scroll to a specific position in listview Flutter?

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.

Is List view scrollable by default?

ListView itself is scrollable.


1 Answers

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.

like image 142
Sertac Akyuz Avatar answered Nov 15 '22 04:11

Sertac Akyuz