...Drag & Drop multiple items within a TListView?

Author: Peter Kooi
Homepage: http://www.gopherpublishers.com

Category: VCL

{ ListView1.DragMode := dmAutomatic }

procedure TForm1.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  
DragItem, DropItem, CurrentItem, NextItem: TListItem;
begin
  if 
Sender = Source then
    with 
TListView(Sender) do
    begin
      
DropItem    := GetItemAt(X, Y);
      CurrentItem := Selected;
      while CurrentItem <> nil do
      begin
        
NextItem := GetNextItem(CurrentItem, SdAll, [IsSelected]);
        if DropItem = nil then DragItem := Items.Add
        else
          
DragItem := Items.Insert(DropItem.Index);
        DragItem.Assign(CurrentItem);
        CurrentItem.Free;
        CurrentItem := NextItem;
      end;
    end;
end;

procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState;
  var Accept: Boolean);
begin
  
Accept := Sender = ListView1;
end;



 

printed from
www.swissdelphicenter.ch
developers knowledge base