TListView支不支持拖放啊?

songwenbo1982 2004-12-31 11:09:56
TListView支不支持拖放啊?如果支持有谁能给个例子,谢谢!
...全文
107 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
songwenbo1982 2004-12-31
  • 打赏
  • 举报
回复
有没有就是在ListView框内的文件变换位置的程序啊?我只想它能够在listview框内拖放就行了
ndujun 2004-12-31
  • 打赏
  • 举报
回复
来晚了,方法同上,能否给2分,哈哈,楼主节日快乐。
xzhifei 2004-12-31
  • 打赏
  • 举报
回复
ListView拖到TreeView:
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
Node: TTreeNode;
begin
with (Sender as TTreeView) do
if GetNodeAt(X, Y) <> nil then
begin
Node := GetNodeAt(X, Y);
ShowMessage('移动到“' + Node.Text + '”!');
end;
end;

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

procedure TForm1.FormCreate(Sender: TObject);
begin
TreeView1.DragMode := dmAutomatic;
ListView1.DragMode := dmAutomatic;
end;


接受资源管理器拖放:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls,shellapi;

type
TForm1 = class(TForm)
ListView1: TListView;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);

end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
//file://设置需要处理文件WM_DROPFILES拖放消息
DragAcceptFiles(ListView1.Handle, TRUE);
//file://设置AppMessage过程来捕获所有消息
Application.OnMessage := AppMessage;

end;
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
var
nFiles, I: Integer;
Filename: string;
ListItem: TListItem;
begin
//
// 注意!所有消息都将通过这里!
// 不要在此过程中编写过多的或者需要长时间操作的代码,否则将影响程序的性能
//
// 判断是否是发送到ListView1的WM_DROPFILES消息
if (Msg.message = WM_DROPFILES) and (msg.hwnd = ListView1.Handle) then
begin
// 取dropped files的数量
nFiles := DragQueryFile (Msg.wParam, $FFFFFFFF, nil, 0);
// 循环取每个拖下文件的全文件名
try
for I := 0 to nFiles - 1 do
begin
// 为文件名分配缓冲 allocate memory
SetLength (Filename, 80);
// 取文件名 read the file name
DragQueryFile (Msg.wParam, I, PChar (Filename), 80);
Filename := PChar (Filename);
//file://将全文件名分解程文件名和路径
ListItem := ListView1.Items.Add;
ListItem.Caption := ExtractFileName(FileName);
ListItem.SubItems.Add(ExtractFilePath(FileName));
end;
finally
//file://结束这次拖放操作
DragFinish (Msg.wParam);
end;
//file://标识已处理了这条消息
Handled := True;
end;
end;
///////////////////////////////
//
//
///////////////////////////////

5,388

社区成员

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

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