Two LISTBOXES and one SCROLLBAR

Two LISTBOXES and one SCROLLBAR

I have any idea how to connect two "listboxes" so that they scroll together in dependence on one "vertical scrollbar".
I would appreciate some advice on how best to do it.
Thanks. Lada.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Is it Win32 or DFLOGM-based dialog?

Two ideas:

1) Subclass the list boxes. In subclassed procedure(s), handle WM_VSCROLL. Scroll the other listbox when "this" one is scrolled.

2) Define a separate scrollbar control. In its callback, scroll both listboxes simultaneously. Remove the "natural" listboxes' scrolbars by removing "vertical scroll" style.

To scroll the listbox programatically:
1) Try sending it a WM_VSCROLL message (I'm not sure it will work, especially if you remove "vertical scroll") or use SetScrollPos API.
2) Send it a LB_SETCURSEL message (that will change the selection as well).

Jugoslav

Jugoslav
www.xeffort.com

It is DFLOGM-based dialog.

In that case, approach 2) looks simpler. Take care that user can navigate through listbox using keyboard arrows -- you have to write DLG_SELCHANGE callbacks to both listboxes as well and set the same selection in the other as well.

Re-thinking about all of it, what's wrong with using one listbox instead if the two are to behave like one? You can conveniently define two "columns" within one list box using "Use tab stops" style. Then, you can send the LB_SETTABSTOPS message on dialog startup to define the tab positions; when filling the listbox, separate "columns" with CHAR(9):

i = DlgSetSub(Dlg, IDD_DIALOG1, OnDialogInit)
DO i = 1, nItems
   i = DlgSet(Dlg, IDC_LIST1, TRIM(sText1)//CHAR(9)//sText2, i)
END DO
...
SUBROUTINE OnDialogInit(Dlg, ID, iEvent)

USE DFLOGM
USE DFWIN

IMPLICIT NONE

INCLUDE "Resource.fd"

TYPE(Dialog)::    Dlg
INTEGER::         ID, iEvent, iSt

INTEGER,PARAMETER::    iTabStop(2)=(/260,300/)

iSt=SendMessage(GetDlgItem(Dlg%Hwnd,IDC_LIST1), &
    LB_SETTABSTOPS, SIZE(iTabStop), LOC(iTabStop))

END SUBROUTINE

Jugoslav

Jugoslav
www.xeffort.com

Thanks a lot for your advice Jugoslav.
It works well. I am very satisfied.
Lada.

Leave a Comment

Please sign in to add a comment. Not a member? Join today