unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls,CommCtrl, StdCtrls;
const
WM_MyInfoMessage=WM_USER + 777;
type
TListView=Class(comCtrls.TListView)
private
FOnItemDeleted: TNotifyEvent;
procedure CNNotify(
var Message: TWMNotifyLV);
message CN_NOTIFY;
Procedure MyInfomessage(
var Message: TWMNotify);
message WM_MyInfoMessage;
published
Property OnItemDeleted:TNotifyEvent
read FOnItemDeleted
write FOnItemDeleted;
End;
TForm2 =
class(TForm)
ListView1: TListView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure OnItemDel(sender: TObject);
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TListView }
procedure TListView.CNNotify(
var Message: TWMNotifyLV);
begin
inherited;
if (
Message.NMHdr.code = LVN_DELETEITEM)
or (
Message.NMHdr.code = LVN_DELETEALLITEMS )
then
if Message.Result=1
then
begin
PostMessage(
Handle,WM_MyInfoMessage,0,0);
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
Showmessage('
Before:'+IntToStr(ListView1.Items.Count));
ListView1.Items.Delete(0);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
ListView1.OnItemDeleted := OnItemDel;
end;
Procedure TForm2.OnItemDel(sender:TObject);
begin
Showmessage('
After:' + IntToStr(TListView(Sender).Items.Count));
end;
procedure TListView.MyInfomessage(
var Message: TWMNotify);
begin
if Assigned(FOnItemDeleted)
then FOnItemDeleted(Self);
end;
end.