Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 83499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:46:59+00:00 2026-05-10T21:46:59+00:00

I’m working on a control to tie together the view from one ListView to

  • 0

I’m working on a control to tie together the view from one ListView to another so that when the master ListView is scrolled, the child ListView view is updated to match.

So far I’ve been able to get the child ListViews to update their view when the master scrollbar buttons are clicked. The problem is that when clicking and dragging the ScrollBar itself, the child ListViews are not updated. I’ve looked at the messages being sent using Spy++ and the correct messages are getting sent.

Here is my current code:

public partial class LinkedListViewControl : ListView {     [DllImport('User32.dll')]     private static extern bool SendMessage(IntPtr hwnd, UInt32 msg, IntPtr wParam, IntPtr lParam);      [DllImport('User32.dll')]     private static extern bool ShowScrollBar(IntPtr hwnd, int wBar, bool bShow);      [DllImport('user32.dll')]     private static extern int SetScrollPos(IntPtr hWnd, int wBar, int nPos, bool bRedraw);      private const int WM_HSCROLL = 0x114;      private const int SB_HORZ = 0;     private const int SB_VERT = 1;     private const int SB_CTL = 2;     private const int SB_BOTH = 3;     private const int SB_THUMBPOSITION = 4;     private const int SB_THUMBTRACK = 5;     private const int SB_ENDSCROLL = 8;      public LinkedListViewControl()     {         InitializeComponent();     }      private readonly List<ListView> _linkedListViews = new List<ListView>();      public void AddLinkedView(ListView listView)     {         if (!_linkedListViews.Contains(listView))         {             _linkedListViews.Add(listView);              HideScrollBar(listView);         }     }      public bool RemoveLinkedView(ListView listView)     {         return _linkedListViews.Remove(listView);     }      private void HideScrollBar(ListView listView)     {         //Make sure the list view is scrollable         listView.Scrollable = true;          //Then hide the scroll bar         ShowScrollBar(listView.Handle, SB_BOTH, false);     }      protected override void WndProc(ref Message msg)     {         if (_linkedListViews.Count > 0)         {             //Look for WM_HSCROLL messages             if (msg.Msg == WM_HSCROLL)             {                 foreach (ListView view in _linkedListViews)                 {                     SendMessage(view.Handle, WM_HSCROLL, msg.WParam, IntPtr.Zero);                 }             }         }     } } 

Based on this post on the MS Tech Forums I tried to capture and process the SB_THUMBTRACK event:

    protected override void WndProc(ref Message msg)     {         if (_linkedListViews.Count > 0)         {             //Look for WM_HSCROLL messages             if (msg.Msg == WM_HSCROLL)             {                 Int16 hi = (Int16)((int)msg.WParam >> 16);                 Int16 lo = (Int16)msg.WParam;                  foreach (ListView view in _linkedListViews)                 {                     if (lo == SB_THUMBTRACK)                     {                         SetScrollPos(view.Handle, SB_HORZ, hi, true);                          int wParam = 4 + 0x10000 * hi;                         SendMessage(view.Handle, WM_HSCROLL, (IntPtr)(wParam), IntPtr.Zero);                     }                     else                     {                         SendMessage(view.Handle, WM_HSCROLL, msg.WParam, IntPtr.Zero);                     }                 }             }         }          // Pass message to default handler.         base.WndProc(ref msg);     } 

This will update the location of the child ListView ScrollBar but does not change the actual view in the child.

So my questions are:

  1. Is it possible to update the child ListViews when the master ListView ScrollBar is dragged?
  2. If so, how?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:47:00+00:00Added an answer on May 10, 2026 at 9:47 pm

    I wanted to do the same thing, and after searching around I found your code here, which helped, but of course didn’t solve the problem. But after playing around with it, I have found a solution.

    The key came when I realized that since the scroll buttons work, that you can use that to make the slider work. In other words, when the SB_THUMBTRACK event comes in, I issue repeated SB_LINELEFT and SB_LINERIGHT events until my child ListView gets close to where the master is. Yes, this isn’t perfect, but it works close enough.

    In my case, my master ListView is called ‘reportView’, while my child ListView is called ‘summaryView’. Here’s my pertinent code:

    public class MyListView : ListView {     public event ScrollEventHandler HScrollEvent;      protected override void WndProc(ref System.Windows.Forms.Message msg)      {         if (msg.Msg==WM_HSCROLL && HScrollEvent != null)             HScrollEvent(this,new ScrollEventArgs(ScrollEventType.ThumbTrack, (int)msg.WParam));          base.WndProc(ref msg);     } } 

    And then the event handler itself:

    reportView.HScrollEvent += new ScrollEventHandler((sender,e) => {     if ((ushort) e.NewValue != SB_THUMBTRACK)         SendMessage(summaryView.Handle, WM_HSCROLL, (IntPtr) e.NewValue, IntPtr.Zero);     else {         int newPos = e.NewValue >> 16;         int oldPos = GetScrollPos(reportView .Handle, SB_HORZ);                          int pos    = GetScrollPos(summaryView.Handle, SB_HORZ);         int lst;          if (pos != newPos)             if      (pos<newPos && oldPos<newPos) do { lst=pos; SendMessage(summaryView.Handle,WM_HSCROLL,(IntPtr)SB_LINERIGHT,IntPtr.Zero); } while ((pos=GetScrollPos(summaryView.Handle,SB_HORZ)) < newPos && pos!=lst);             else if (pos>newPos && oldPos>newPos) do { lst=pos; SendMessage(summaryView.Handle,WM_HSCROLL,(IntPtr)SB_LINELEFT, IntPtr.Zero); } while ((pos=GetScrollPos(summaryView.Handle,SB_HORZ)) > newPos && pos!=lst);         }     }); 

    Sorry about the odd formatting of the while loops there, but that’s how I prefer to code things like that.

    The next problem was getting rid of the scroll bars in the child ListView. I noticed you had a method called HideScrollBar. This didn’t really work for me. I found a better solution in my case was leaving the scroll bar there, but ‘covering’ it up instead. I do this with the column header as well. I just slide my child control up under the master control to cover the column header. And then I stretch the child to fall out of the panel that contains it. And then to provide a bit of a border along the edge of my containing panel, I throw in a control to cover the visible bottom edge of my child ListView. It ends up looking rather nice.

    I also added an event handler to sync changing column widths, as in:

    reportView.ColumnWidthChanging += new ColumnWidthChangingEventHandler((sender,e) => {     summaryView.Columns[e.ColumnIndex].Width = e.NewWidth;     });          

    While this all seems a bit of a kludge, it works for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.