1

I'm trying to sync up 2 list views, so that one of them is effectively a 'freeze pane' of one column (think excel freeze-headers).

However, I am having difficulty in getting the top items to sync up when scrolling. I need to hide the vertical and horizontal scrollbars on the header-list view, which can be achieved by setting Scrollable to false. Though this seems to disable the 'EnsureVisible' and 'TopItem' functionality?

I have intercepted the scroll bar messages on the master listview, so I know when that is being scrolled, just for some reason I'm unable to update the top item on the header listview to match up.

The code I have for updating the header listview is as follows:

//On vertical scroll click...
  if (e.Type == ScrollEventType.EndScroll)
  {
    int index = lvwHeader.FindItemWithText(lvwSource.TopItem.Text).Index;

    ListViewItem item = lvwHeader.Items[index];
    lvwHeader.TopItem = item;

    System.Diagnostics.Debug.WriteLine(lvwHeader.TopItem.Text + " - " + lvwSource.TopItem.Text);
  }

So I was wondering if there was another way to force the header listview to set an item as the topitem whilst Scrollable = false, or if there was a better way to approach this?

Many thanks

ChrisD88
  • 25
  • 4
  • 1
    Rather a lot of reasons to make the 'header' not a ListView. – Hans Passant Aug 30 '11 at 10:28
  • I did contemplate that, but thought it would probably be more difficult in the long run, especially to do with formatting as it has to look like one seemless control, so the column titles could be tricky? What other control could you suggest? Thanks – ChrisD88 Aug 30 '11 at 10:37
  • Could you temporarily set scrollable to true, do your stuff, then set it back to false if that's what's causing your problem? – andyhasit Aug 30 '11 at 13:59
  • Unfortunately not Andy, when disabling Scrollable again it seems to set the control back into it's initial state – ChrisD88 Aug 30 '11 at 14:16
  • Check out this link: http://stackoverflow.com/questions/2488622/how-to-hide-the-vertical-scroll-bar-in-a-net-listview-control-in-details-mode . Is that of any help? – andyhasit Aug 30 '11 at 15:39
  • 1
    I'm sure this isn't the answer you want to hear, but this isn't a .NET limitation, it's a hard limitation of the Win32 ListView control. The `EnsureVisible` function in .NET just sends the underlying ListView control an `LVM_ENSUREVISIBLE` message, and as [the documentation for that message](https://msdn.microsoft.com/en-us/library/windows/desktop/bb774902.aspx) indicates, this message has no effect if scrolling is disabled because the ListView control has the `LVS_NOSCROLL` style (which is the effect of setting the Scrollable property to false). – Cody Gray - on strike Jan 10 '16 at 11:56

0 Answers0