Solved

ListBox OnScroll

Posted on 1999-01-25
4
1,305 Views
Last Modified: 2012-06-27
I need OnScrool event for list boxes. How to make it?

In fact I want two list boxes to be synchronized, ie when user scrolls through first, the second follows it automatically...
0
Comment
Question by:yuhoo
  • 2
4 Comments
 
LVL 4

Expert Comment

by:BoRiS
ID: 1363331
yuhoo

You can use the GetScrollInfo and the SetScrollInfo API calls to synchronize the listboxs something like...

GetScrollinfo(Listbox1.Handle, SB_CTL, SIF_POS or SIF_RANGE or SIF_PAGE );

SetScrollinfo(Listbox2.Handle, SB_CTL, SIF_POS or SIF_RANGE or SIF_PAGE, True);

To create an OnScroll event you can try this...it's just an example I have not tested it so I'm not sure if it will work....

private
FOnScroll : TNotifyEvent;

protected
procedure CMScroll(var Message: TMessage); message CM_SCROLL;

published
property OnScroll: TNotifyEvent read FOnScroll write FOnScroll;

then the procedure...

procedure TListBoxEx.CMScroll(var Message: TMessage);
begin
  inherited;
    if Assigned (FOnScroll) then FOnScroll(Self);
end;

Later
BoRiS
0
 
LVL 17

Expert Comment

by:inthe
ID: 1363332
hi
there is a component on delphi super page to do this.
http://sunsite.icm.edu.pl/delphi/

it's called something like hslistbox.zip
i not tried it myself but supposed to be ok.
Regards Barry
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1363333
yuhoo

You can use the GetScrollInfo and the SetScrollInfo API calls to synchronize the listboxs something like...

GetScrollinfo(Listbox1.Handle, SB_CTL, SIF_POS or SIF_RANGE or SIF_PAGE );

SetScrollinfo(Listbox2.Handle, SB_CTL, SIF_POS or SIF_RANGE or SIF_PAGE, True);

To create an OnScroll event you can try this...it's just an example I have not tested it so I'm not sure if it will work....

private
FOnScroll : TNotifyEvent;

protected
procedure CMScroll(var Message: TMessage); message CM_SCROLL;

published
property OnScroll: TNotifyEvent read FOnScroll write FOnScroll;

then the procedure...

procedure TListBoxEx.CMScroll(var Message: TMessage);
begin
  inherited;
    if Assigned (FOnScroll) then FOnScroll(Self);
end;

Later
BoRiS
0
 

Accepted Solution

by:
earthworm earned 50 total points
ID: 1363334
It's a good idea to process the Scoll message,but if you don't want to write a new component,you can try this:
you can set the property "Style" of the listbox to "lbOwnerDrawFixed",so the ListBox wil occur the "OnDrawItem" Even when it be scrolled and you can Synchronized the listbox on this event, BUT YOU MUST DRAW THE ITEMS IN THE LISTBOX YOURSELF,SORRY.

by the way, you can synchronize the listboxes by this way:
  ListBox2.TopIndex:=ListBox1.TopIndex;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 77
delphi parse string to params 3 97
LAN or WAN ? 11 81
Multiple image collision 13 69
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now