Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would create my own class, inheriting from ListView to expose the Vertical and Horizontal scroll events.</p> <p>Then I would do create scroll handlers in my form to synchronize the two controls</p> <p>This is sample code which should allow a listview to publish scroll events:</p> <pre><code>public class MyListView : System.Windows.Forms.ListView { const int WM_HSCROLL = 0x0114; const int WM_VSCROLL = 0x0115; private ScrollEventHandler evtHScroll_m; private ScrollEventHandler evtVScroll_m; public event ScrollEventHandler OnHScroll { add { evtHScroll_m += value; } remove { evtHScroll_m -= value; } } public event ScrollEventHandler OnHVcroll { add { evtVScroll_m += value; } remove { evtVScroll_m -= value; } } protected override void WndProc(ref System.Windows.Forms.Message msg) { if (msg.Msg == WM_HSCROLL &amp;&amp; evtHScroll_m != null) { evtHScroll_m(this,new ScrollEventArgs(ScrollEventType.ThumbTrack, msg.WParam.ToInt32())); } if (msg.Msg == WM_VSCROLL &amp;&amp; evtVScroll_m != null) { evtVScroll_m(this, new ScrollEventArgs(ScrollEventType.ThumbTrack, msg.WParam.ToInt32())); } base.WndProc(ref msg); } </code></pre> <p>Now handle the scroll events in your form:</p> <p>Set up a PInvoke method to be able to send a windows message to a control:</p> <pre><code>[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int SendMessage(IntPtr hWnd, [MarshalAs(UnmanagedType.U4)] int iMsg, int iWParam, int iLParam); </code></pre> <p>Set up your event handlers (lstMaster and lstChild are two listboxes):</p> <pre><code>lstMaster.OnVScroll += new ScrollEventHandler(this.lstMaster_OnVScroll); lstMaster.OnHScroll += new ScrollEventHandler(this.lstMaster_OnHScroll); const int WM_HSCROLL = 0x0114; const int WM_VSCROLL = 0x0115; private void lstMaster_OnVScroll(Object sender, System.ScrollEventArgs e) { SendMessage(lstChild.Handle,WM_VSCROLL,(IntPtr)e.NewValue, IntPtr.Zero); } private void lstMaster_OnHScroll(Object sender, System.ScrollEventArgs e) { SendMessage(lstChild.Handle,WM_HSCROLL,(IntPtr)e.NewValue, IntPtr.Zero); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload