怎样实现拖动Tlistview控件里的item项上下调位置

lcmlhs_2005 2011-01-22 08:42:01
旷世难题,怎样实现拖动Tlistview控件里的item项上下调位置,高手进,在线急等之?
...全文
127 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lcmlhs_2005 2011-01-28
  • 打赏
  • 举报
回复
楼上教训的是,那日我已经触类旁通了,只是太忙,没来得及结帖,现在结帖
JPEXE 2011-01-24
  • 打赏
  • 举报
回复
有了3楼的代码,楼主你就应该触类旁通了……
ecjtu5208 2011-01-24
  • 打赏
  • 举报
回复
再次发现旷世难题。
lcmlhs_2005 2011-01-23
  • 打赏
  • 举报
回复
楼上的不错,可是你的拖动只是把拖动的item与目的的item相调换,我的要求不是调换,而是按顺序依次排列,比如,我向上拖的时候,目的item要向下移动,反之入下拖的时候,目的item向上移动
bdmh 2011-01-23
  • 打赏
  • 举报
回复
写的有点乱

ListView1.DragMode := dmAutomatic;


procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := True;
end;

procedure TForm1.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
DragItem,item,item1,item2:TListItem;
index:Integer;
begin
item := ListView1.GetItemAt(x,y);
if item = nil then Exit;
DragItem := ListView1.Selected;
index := ListView1.DropTarget.Index;
if index > DragItem.Index then
begin
item1:=ListView1.Items.Insert(index+1);
item2 := ListView1.Items.Insert(DragItem.Index);
end
else
begin
item1:=ListView1.Items.Insert(index);
item2:=ListView1.Items.Insert(DragItem.Index);
end;
item1.Assign(DragItem);
item2.Assign(item);
DragItem.Delete;
item.Delete;
ListView1.Refresh;
end;
Frank.WU 2011-01-22
  • 打赏
  • 举报
回复
这个也算难题?可见楼主多么的懒,网络上大把这种代码。
cntigercat 2011-01-22
  • 打赏
  • 举报
回复
sf

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧