起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 398|回复: 4

【结】ListBox怎么实现用鼠标来调动数据的上下位置?

[复制链接]
发表于 2010-10-26 16:59:30 | 显示全部楼层 |阅读模式
如题
怎么实现用鼠标任意调上下位置??
回复

使用道具 举报

发表于 2010-10-27 08:53:54 | 显示全部楼层
百度一下,delphi的相关资料。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-10-28 15:49:53 | 显示全部楼层
DragFile,popFile:String;//拖动的文件名 (全局)  

procedure   TfrmMain.lbxMyListClick(Sender:   TObject);   
begin   //单击时确定要拖动的文件名   
    if   TListbox(Sender).ItemIndex   <>-1   then   
        DragFile:=TListbox(Sender).Items[TListbox(Sender).itemIndex]   
    else   
        DragFile:=’’;   
end;   

procedure   TfrmMain.lbxMyListDragOver(Sender,   Source:   TObject;   X,   Y:   

Integer;   
    State:   TDragState;   var   Accept:   Boolean);   
var   
    i,j:integer;   
    FileName:string;   
    MyPoint:TPoint;   
begin   //在列表框中拖动项目改变其位置   
    if   DragFile<>’’   then   
    begin   
        MyPoint.X:=X;     MyPoint.Y:=Y;   
        i:=TListbox(Sender).ItemAtPos(MyPoint,True);//获取要拖放到的位置   
        j:=   TListbox(Sender).Items.IndexOf(DragFile);   
        if   (i<>-1)   and   (j<>-1)   and   (i<>j)   then   
        begin   
                TListbox(Sender).Items.Move(j,i);   
                TListbox(Sender).Selected:=True;   
        end;   
    end;   
end;
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-10-28 15:54:20 | 显示全部楼层
dragMode属性改成dmAutomatic
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-10-28 15:55:26 | 显示全部楼层
结贴
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-6 19:04 , Processed in 0.040466 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表