0

I have two list controls and both are vertically scroll-able separately.

However I want to synchronize scroll also I would like to hide the vertical scroll bar in list control-1.

On the other hand if you scroll vertically list control-2, then the list control-1 should scroll down automatically the same amount of items in such way that the options on the both the list boxes should always appear in the same row.

How can I achieve this in MFC?

enter image description here

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Tuvi
  • 63
  • 1
  • 10
  • For synchronizing you can use `CListBox::SetTopIndex` and `CListBox::SetTopIndex`. Hiding the scroll bar in a listbox that has more items than can be displayed is another story, I'm not sure if this is possible. You may try to owner draw the list control , then you are in total control of what is displayed in list control 1, but that requires some work. – Jabberwocky Mar 30 '16 at 07:19
  • Correction: you can remove the vertical scrollbar by setting the "Vertical scrollbar" property of the listbox to False. – Jabberwocky Mar 30 '16 at 07:38
  • @MichaelWalz thank you for your reply. Is it possible to make freeze (fix) first column of list control? i mean that same as freeze column in Excel. – Tuvi Mar 30 '16 at 07:39
  • Not quite sure what you mean by _first column_, I thought you had _two_ list controls. Maybe you should edit your question makeing more clear what exactly you want. – Jabberwocky Mar 30 '16 at 07:41
  • ooh my bad...fist column i mean list control-1. – Tuvi Mar 30 '16 at 07:45
  • Just remove the scroll bar from the first list control. Then you are in total control of what will be displayed in this list control using `CListCtrl::SetTopIndex`. – Jabberwocky Mar 30 '16 at 07:57
  • There is CListCtrl::GetTopIndex(); but there is not CListCtrl::SetTopIndex(). Instead of i used EnsureVisible(). – Tuvi Mar 30 '16 at 09:21
  • 1
    Sorry, I misread your question thinking you were talking about list boxes and not list controls. Have a look at [this SO question](http://stackoverflow.com/questions/35203324/list-control-lvm-settopindex-needed). – Jabberwocky Mar 30 '16 at 09:26

1 Answers1

0

I do this with a connection between two list views through the document, but the end result is a command to the Scroll member of the slave list control.

So handle the ON_WM_VSCROLL() in the master, I actually have a custom notify but you may want to just shortcut to from the likes of in the master:

if( pS->nSBCode == SB_THUMBTRACK )
    GetDocument( )->SetSplitScrollPos( pS->nPos );

How ever you work past to the likes of 'SetSplitScrollPos' it ends up with this at the slave:

void CLCtrl::ScrollToVPosition( long inPos )
{
    long scroll= ( inPos - curVScrollPos );
    Scroll( scroll << 20 );
    curVScrollPos= inPos;
}

The 'Scroll' call is a CListCtrl member, so you could:

mySlaveCtrl.Scroll( ... );

Now, I'm sorry, but I don't recall why the shift of 20 as '<< 16' should move the value to the hi_word, but it needed to be 16 times greater, (20 - 16). I did not write in the required comments.

To wit, it may be as simple for you to handle the master ON_WM_VSCROLL and:

if( pS->nSBCode == SB_THUMBTRACK )
    mySlaveCtrl.Scroll( ( ps->pos - curVScrollPos ) << 20 );
lakeweb
  • 1,859
  • 2
  • 16
  • 21
  • thank you so much for your replay. i refer [link](http://stackoverflow.com/questions/35203324/list-control-lvm-settopindex-needed) – Tuvi Apr 01 '16 at 07:40