Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ListBox OnScroll

Posted on 1999-01-25
4
1,334 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

790 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