Thursday, 4 June 2009


The .net TreeView doesn't expose a scroll event. Make your own by overriding DefWndProc.

   public class TreeViewScroll : TreeView
private const int WM_VSCROLL = 0x115;
private IntPtr SB_ENDSCROLL = new IntPtr(8);

public event MethodInvoker Scroll;

protected void OnScroll()
if (Scroll != null)

protected override void DefWndProc(ref Message m)
if (m.Msg == WM_VSCROLL)
if (m.WParam != SB_ENDSCROLL)

base.DefWndProc(ref m);

The code above is sufficient for my needs, but if you need more details about the scroll (direction, where you scrolled to, etc) you need to interrogate the message further.

This link should tell you what the message contains:

This link can tell you the scrollbar values:

No comments: