Delphi TListview[3]实现拖拽功能
Delphi TListview[3]实现拖拽功能
1、设置ListView1的属性:
Listview1.DragMode:=dmAutomatic;
2、OnDragOver事件:
procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin Accept := True; end;
3、OnDragDrop事件:
procedure TForm1.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
aItem, bItem: TListItem;
begin
if (Source is TListView) then
begin
bItem := (Source as TListView).Selected;
aItem := (Source as TListView).Items.Insert((Source as TListView).Items.IndexOf((Source as TListView).GetItemAt(X, Y)));
aItem.Assign(bItem);
(Source as TListView).Selected.Delete;
aItem.Selected := True;
end;
end;
创建时间:2020.03.20 更新时间:
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!