ListView的拖动问题(100分)

  • 主题发起人 主题发起人 晓鹤
  • 开始时间 开始时间

晓鹤

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
ListView1: TListView;
procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure ListView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ListView1.BeginDrag(False,3);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
i,j:integer;
Item:TListItem;
begin
for i := 0 to 9 do
begin
Item := ListView1.Items.Add;
Item.Caption := IntToStr(i);
for j := 1 to 3 do
begin
Item.SubItems.Add(IntToStr(i) + IntToStr(j));
end;
end;
end;

procedure TForm1.ListView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if (State = dsDragMove) and (Source = ListView1) then
Accept := True;
if State = dsDragLeave then
TControl(Sender).EndDrag(True);
end;

end.

每次拖动离开ListView时错误,为什么?
 
是TControl(Sender).EndDrag(True);这句话报的错。可能是不应该调用EndDrag
 
我就是想取消拖动。
 
采用键盘消息解决:
PostMessage(ListView1.Handle,WM_KEYDOWN,VK_ESCAPE ,1);
PostMessage(ListView1.Handle,WM_KEYUP,windows.VK_ESCAPE,1);
 

Similar threads

I
回复
0
查看
724
import
I
I
回复
0
查看
566
import
I
I
回复
0
查看
509
import
I
后退
顶部