Delphi ListView Drag the entire row

I am new to the drag and drop system in Delphi for ListView. I found a simple solution on the web to drag and drop items into a ListView. The problem is that the code only shows the drag of the first column, and I want to show and drag the whole row.

In the following figure, you can see what I get and what I want.

Drag and Drop 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; 
+5
source share
1 answer

I don’t know how you get a snapshot of the selected current row, but part of its drag and drop looks like this:

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

You can create a bitmap and manually draw an element in it.

Or here's how to take a screenshot of the entire list (or any other component): http://delphidabbler.com/tips/24 You can determine the coordinates of an element and copy it from the screen to a new bitmap.

0
source

Source: https://habr.com/ru/post/1239421/


All Articles