2015-12-29 30 views
5

私はListViewのためのDelphiのドラッグアンドドロップシステムには全く新しいです。私はListViewの項目をドラッグアンドドロップする簡単なソリューションをインターネット上で見つけました。問題は、コードが最初の列をドラッグするだけで表示され、が表示され、と表示され、行全体がドラッグされてしまうことです。Delphi ListViewドラッグドロップ全体行

次の画像では、取得した内容と取得したい内容を確認できます。

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 –

答えて

0

私はあなたが選択した現在の行のスナップショットを取得する方法を知りませんが、それをドラッグ&ドロップの部分はこのようなものです:

// 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; 

あなたが作成することができますビットマップ内にアイテムを手動で描画します。

それともここで全体のリストビュー(または他のコンポーネント)のスクリーンショットを作成する方法である: http://delphidabbler.com/tips/24 あなたはアイテムの座標を把握し、新しいビットマップにスクリーンショットから、それをコピーすることができます。

関連する問題