How synchronize two list controls vertically in MFC

704 Views Asked by At

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

1

There are 1 best solutions below

1
lakeweb On

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 );