2015-12-29 22 views
5

Sono abbastanza nuovo per il sistema di trascinamento e rilascio di Delphi per ListView. Ho trovato una soluzione semplice su Internet per trascinare elementi in ListView. Il problema è che il codice mostra solo il trascinamento della prima colonna e voglio mostrare e trascinare l'intera riga.Delphi ListView Trascina tutta la riga

È possibile visualizzare nella figura seguente ciò che ottengo e ciò che voglio ottenere.

Dragging and Dropping in Delphi

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; 

self.ListView1.DragMode := dmAutomatic; 
+1

http://docwiki.embarcadero.com/RADStudio/Seattle/en/Customizing_Drag_and_Drop_with_a_Drag_Object –

risposta

0

Non so come si ottiene un'istantanea della riga corrente selezionata, ma la parte di trascinamento di esso è in questo modo:

// you need a TDragControlObject: 
    TPlainDragControlObject = class(TDragControlObject) 
    protected 
    function GetDragImages: TDragImageList; override; 
    End; 
..... 

Implementation 

function TPlainDragControlObject.GetDragImages: TDragImageList; 
var 
    images : TDragImageList; 
begin 
    images := TDragImageList.create(self); 
    // ToDo: add images - how the drag object will look like 

    Result := images; // you can return Nil here if you want just the drag cursor with no image at all 
end; 

procedure TMainForm.lvStartDrag(Sender: TObject; 
    var DragObject: TDragObject); 
begin 
    If Sender = ListView1 Then Begin 
    DragObject := TPlainDragControlObject.Create(Sender as TListView); 
    End; 
end; 

È possibile creare un bitmap e disegnare manualmente l'elemento in esso.

O qui è come fare uno screenshot di tutta la vista elenco (o qualsiasi altro componente): http://delphidabbler.com/tips/24 si può capire le coordinate voce e copiarlo dallo screenshot in una nuova bitmap.