Solved

ListBox OnScroll

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

16 Experts available now in Live!

Get 1:1 Help Now