<div>Don't forget "scrolling" also occurs when you use the arrow keys.</div>
<div> </div>
<div>My contribution (just made up then)...</div>
<div> </div>
<div>unit ScrollingListView;</div>
<div> </div>
<div>interface</div>
<div> </div>
<div>uses<br> Windows, Messages, ComCtrls, CommCtrl, Controls;</div>
<div> </div>
<div>type<br> TJSListView = class(TListView)<br> private<br> type<br> TJSScrollEvent = procedure (Sender: TObject; const BeginScroll: Boolean) of object;<br> var<br> FOnEndScroll: TJSScrollEvent;<br> FOnBeginScroll: TJSScrollEvent;<br>
protected<br> procedure DoScroll(const AStart: Boolean); virtual;<br> procedure CNNotify(var Message: TWMNotifyLV); message CN_NOTIFY;<br> public<br> property OnBeginScroll: TJSScrollEvent read FOnBeginScroll write FOnBeginScroll;<br>
property OnEndScroll: TJSScrollEvent read FOnEndScroll write FOnEndScroll;<br> end;</div>
<div> </div>
<div>implementation</div>
<div> </div>
<div>{ TJSListView }</div>
<div> </div>
<div>procedure TJSListView.CNNotify(var Message: TWMNotifyLV);<br>begin<br> if Message.NMHdr.code = -180 then // LVM_BEGINSCROLL<br> begin<br> DoScroll(True);<br> end;<br> if Message.NMHdr.code = -181 then // LVM_ENDSCROLL<br>
begin<br> DoScroll(False);<br> end;<br> inherited;<br>end;</div>
<div> </div>
<div>procedure TJSListView.DoScroll(const AStart: Boolean);<br>var<br> LEvent: TJSScrollEvent;<br>begin<br> if AStart then<br> LEvent := OnBeginScroll<br> else<br> LEvent := OnEndScroll;<br> if Assigned(LEvent) then<br>
LEvent(Self, AStart);<br>end;</div>
<div> </div>
<div>end.<br></div>
<div> </div>
<div><br><br> </div>
<div class="gmail_quote">On Fri, Feb 25, 2011 at 2:01 PM, David O'Brien <span dir="ltr"><<a href="mailto:Dave@iccs.co.nz">Dave@iccs.co.nz</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div lang="EN-NZ" vlink="purple" link="blue">
<div>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">Sorted it thanks, had mixed versions of code in the component. The events do fire…</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<div>
<div style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<p class="MsoNormal"><b><span style="FONT-SIZE: 10pt" lang="EN-US">From:</span></b><span style="FONT-SIZE: 10pt" lang="EN-US"> <a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a> [mailto:<a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a>] <b>On Behalf Of </b>Jolyon Smith<br>
<b>Sent:</b> Friday, 25 February 2011 3:43 p.m.
<div class="im"><br><b>To:</b> 'NZ Borland Developers Group - Delphi List'<br></div><b>Subject:</b> Re: [DUG] Listview problem</span>
<p></p></p></div></div>
<div>
<div></div>
<div class="h5">
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">A WM_VSCROLL message handler works perfectly for me.</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">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 ?</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">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.</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">In my list view class I have:</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> TScrollNotification = (</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snBeforeHScroll,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snBeforeHWheel,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snBeforeVScroll,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snBeforeWheel,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snHScroll,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snHWheel,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snVScroll,</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> snWheel</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> );</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> procedure TXListview.WMVScroll(var aMessage: TWMVScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> DoScroll(snBeforeVScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> inherited;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> DoScroll(snVScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> procedure TXListview.WMHScroll(var aMessage: TWMHScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> DoScroll(snBeforeHScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> inherited;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> DoScroll(snHScroll);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">and similar for mousewheel messages of course, where DoScroll:</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> procedure TXListview.DoScroll(const aNotification: TScrollNotification);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> if (aNotification in [snBeforeHScroll, snBeforeVScroll, snBeforeHWheel, snBeforeWheel]) then</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> CancelEdit;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> if Assigned(fOnScroll) then</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> fOnScroll(self, aNotification);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">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.</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">hth</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<div>
<div style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<p class="MsoNormal"><b><span style="FONT-SIZE: 10pt" lang="EN-US">From:</span></b><span style="FONT-SIZE: 10pt" lang="EN-US"> <a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a> [mailto:<a href="mailto:delphi-bounces@delphi.org.nz" target="_blank">delphi-bounces@delphi.org.nz</a>] <b>On Behalf Of </b>David O'Brien<br>
<b>Sent:</b> Friday, 25 February 2011 15:09<br><b>To:</b> NZ Borland Developers Group - Delphi List<br><b>Subject:</b> [DUG] Listview problem</span></p></div></div>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">I am working on an application (D2009) where I need to know when a TListView is Scrolled.</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">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:</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> TLVScrollEvent = procedure(Sender: TObject) of object;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> TICListView = class(TListView)</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> private</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> FOnScroll: TLVScrollEvent;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> protected</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> Procedure WMVScroll( Var Msg: TMessage ); message WM_VSCROLL;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> Procedure WMHScroll( Var Msg: TMessage ); message WM_HSCROLL;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> property OnScroll: TLVScrollEvent read FOnScroll write FOnscroll ;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">procedure Register ;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">implementation</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">procedure Register;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> RegisterComponents('Dave', [TICListView]);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">procedure TICListView.WMHScroll(var Msg: TMessage);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> OnScroll ;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> inherited;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">procedure TICListView.WMVScroll(var Msg: TMessage);</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">begin</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> OnScroll ;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> inherited;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt">end;</span></p>
<p class="MsoNormal"><span style="COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">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…</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">Anyone have a solution?</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt"> </span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">Regards,</span></p>
<p class="MsoNormal"><span style="FONT-SIZE: 11pt">Dave.</span></p></div></div></div></div><br>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><br>
Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<br>
</blockquote></div><br>