Don't forget "scrolling" also occurs when you use the arrow keys.
My contribution (just made up then)... unit ScrollingListView; interface uses Windows, Messages, ComCtrls, CommCtrl, Controls; type TJSListView = class(TListView) private type TJSScrollEvent = procedure (Sender: TObject; const BeginScroll: Boolean) of object; var FOnEndScroll: TJSScrollEvent; FOnBeginScroll: TJSScrollEvent; protected procedure DoScroll(const AStart: Boolean); virtual; procedure CNNotify(var Message: TWMNotifyLV); message CN_NOTIFY; public property OnBeginScroll: TJSScrollEvent read FOnBeginScroll write FOnBeginScroll; property OnEndScroll: TJSScrollEvent read FOnEndScroll write FOnEndScroll; end; implementation { TJSListView } procedure TJSListView.CNNotify(var Message: TWMNotifyLV); begin if Message.NMHdr.code = -180 then // LVM_BEGINSCROLL begin DoScroll(True); end; if Message.NMHdr.code = -181 then // LVM_ENDSCROLL begin DoScroll(False); end; inherited; end; procedure TJSListView.DoScroll(const AStart: Boolean); var LEvent: TJSScrollEvent; begin if AStart then LEvent := OnBeginScroll else LEvent := OnEndScroll; if Assigned(LEvent) then LEvent(Self, AStart); end; end. On Fri, Feb 25, 2011 at 2:01 PM, David O'Brien <d...@iccs.co.nz> wrote: > Sorted it thanks, had mixed versions of code in the component. The events > do fire… > > > > *From:* delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] > *On Behalf Of *Jolyon Smith > *Sent:* Friday, 25 February 2011 3:43 p.m. > > *To:* 'NZ Borland Developers Group - Delphi List' > *Subject:* Re: [DUG] Listview problem > > > > A WM_VSCROLL message handler works perfectly for me. > > > > However, this will only be sent for scrollbar directed scrolling. To also > handle mousewheel scrolling you will have to implement a WM_MOUSEWHEEL > message handler (and WM_HMOUSEWHEEL if appropriate to your needs). Could > it be mouse scrolling that you are missing ? > > > > I would also note that you will almost certainly want to distinguish > between H and V scrolling, rather than have a “universal” “some sort of > scrolling has occurred” notification. You may also wish to be able to > respond both before and after scrolling has occurred. > > > > > > In my list view class I have: > > > > TScrollNotification = ( > > snBeforeHScroll, > > snBeforeHWheel, > > snBeforeVScroll, > > snBeforeWheel, > > snHScroll, > > snHWheel, > > snVScroll, > > snWheel > > ); > > > > > > procedure TXListview.WMVScroll(var aMessage: TWMVScroll); > > begin > > DoScroll(snBeforeVScroll); > > inherited; > > DoScroll(snVScroll); > > end; > > > > procedure TXListview.WMHScroll(var aMessage: TWMHScroll); > > begin > > DoScroll(snBeforeHScroll); > > inherited; > > DoScroll(snHScroll); > > end; > > > > > > > > and similar for mousewheel messages of course, where DoScroll: > > > > > > procedure TXListview.DoScroll(const aNotification: TScrollNotification); > > begin > > if (aNotification in [snBeforeHScroll, snBeforeVScroll, snBeforeHWheel, > snBeforeWheel]) then > > CancelEdit; > > > > if Assigned(fOnScroll) then > > fOnScroll(self, aNotification); > > end; > > > > > > i.e. my listview also provides a facility for sub-item editing and when > scrolling occurs, the first thing I do before doing the actual scrolling is > dismiss any sub-item editor that may be active, before then firing the > OnScroll event to allow my application code to respond as it may require. > > > > hth > > > > > > *From:* delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] > *On Behalf Of *David O'Brien > *Sent:* Friday, 25 February 2011 15:09 > *To:* NZ Borland Developers Group - Delphi List > *Subject:* [DUG] Listview problem > > > > I am working on an application (D2009) where I need to know when a > TListView is Scrolled. > > I have used Application.OnMessage to look for WM_VScroll messages, but they > do not happen, also have tried creating the below which I thought should > work: > > > > TLVScrollEvent = procedure(Sender: TObject) of object; > > > > TICListView = class(TListView) > > private > > FOnScroll: TLVScrollEvent; > > protected > > Procedure WMVScroll( Var Msg: TMessage ); message WM_VSCROLL; > > Procedure WMHScroll( Var Msg: TMessage ); message WM_HSCROLL; > > property OnScroll: TLVScrollEvent read FOnScroll write FOnscroll ; > > end; > > > > procedure Register ; > > > > implementation > > > > procedure Register; > > begin > > RegisterComponents('Dave', [TICListView]); > > end; > > > > procedure TICListView.WMHScroll(var Msg: TMessage); > > begin > > OnScroll ; > > inherited; > > end; > > > > procedure TICListView.WMVScroll(var Msg: TMessage); > > begin > > OnScroll ; > > inherited; > > end; > > > > which also doesn’t fire. I have written a list of all messages fired when > the scrollbar is moved, but there doesn’t seem to be anything useful… > > > > Anyone have a solution? > > > > Regards, > > Dave. > > _______________________________________________ > NZ Borland Developers Group - Delphi mailing list > Post: delphi@delphi.org.nz > Admin: http://delphi.org.nz/mailman/listinfo/delphi > Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: > unsubscribe >
_______________________________________________ NZ Borland Developers Group - Delphi mailing list Post: delphi@delphi.org.nz Admin: http://delphi.org.nz/mailman/listinfo/delphi Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: unsubscribe