title: How do I sync scrolling in two treeviews using the slider
body: <p>I am using Visual&nbsp;Studio&nbsp;2010 (C#) and a Windows Forms application.</p>
  
  <p>I have two treeviews side by side, and I have figured out how to synchronise the scrolling using the up/down buttons on the scrollbar, but when I use the slider it does not move the other treeview. I have taken a listview example that works, but the same code does not work for treeviews.</p>
  
  <p>So far I have, in the main form:</p>
  
  <pre><code>    [DllImport("User32.dll")]
      public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
  
      private void myListBox1_Scroll(ref Message m)
      {
          SendMessage(myListBox2.Handle, (uint)m.Msg, (uint)m.WParam, (uint)m.LParam);
      }
  </code></pre>
  
  <p>I have created a control:</p>
  
  <pre><code>public partial class MyTreeView : TreeView
  {
      public MyTreeView()
      {
          InitializeComponent();
      }
  
      public event ScrollEventHandler Scroll;
      public delegate void ScrollEventHandler(ref Message m);
  
  
      private const int WM_VSCROLL = 0x115;
  
      protected override void WndProc(ref System.Windows.Forms.Message m)
      {
          if (m.Msg == WM_VSCROLL)
              if (Scroll != null)
              {
                  Scroll(ref m);
              }
  
          base.WndProc(ref m);
      }
  
  }
  </code></pre>
  
  <p>which I add two of to the form.</p>
  
  <p>I can use the same code to have a listivew control the treeview and that will work if you drag the slider, but in reverse it only works with the up down buttons.</p>