gpt4 book ai didi

Delphi ListView拖放整行

转载 作者:行者123 更新时间:2023-12-03 15:02:37 26 4
gpt4 key购买 nike

我对 Delphi 中 ListView 的拖放系统非常陌生。我在互联网上找到了一个简单的解决方案,可以在 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;

最佳答案

我不知道如何获取所选当前行的快照,但它的拖放部分是这样的:

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

您可以创建位图并在其中手动绘制项目。

或者here is how to make a screenshot of the whole listview (or any other component) 。您可以计算出项目坐标并将其从屏幕截图复制到新的位图中。

关于Delphi ListView拖放整行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34510144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com