Board index » delphi » Getting rid of scrollbar in Listbox

Getting rid of scrollbar in Listbox

Hi,
I have : Listbox1 and Listbox2.
They are positioned next to eachother. They have the same number of
items and when the user
select an item : Listbox1.itemindex:=Listbox2.itemindex (and vice
versa).
No problems so far.
But when there are more items the fit in the visible part automatically
two scrollbars appear.
Now I'd like to
1) get rid of scrollbar of Listbox1
2) use scrollbar of Listbox2 to control both  Listbox1 and  Listbox2

any ideas on how to do this ?

Thanks,
Bhas

 

Re:Getting rid of scrollbar in Listbox


Hi Bhas.

Quote
>I have : Listbox1 and Listbox2.
>They are positioned next to eachother. They have the same number of
>items and when the user
>select an item : Listbox1.itemindex:=Listbox2.itemindex (and vice
>versa).
>No problems so far.
>But when there are more items the fit in the visible part automatically
>two scrollbars appear.
>Now I'd like to
>1) get rid of scrollbar of Listbox1

Inprise decided not to put a property for the presence of scroll bars in
their TListBox control for some reason, but you can get around it with
fairly minimal fuss.

Create a new component derived from TListBox and call it TListBoxNoScroll or
something.  Then, in the protected part of the component's declaration, put
the header:

    procedure CreateParams(var Params: TCreateParams); override;

Then, in the implementation part of the unit, write the following procedure:

    procedure TListBoxNoScoll.CreateParams(var Params: TCreateParams);
    begin
      inherited CreateParams(Params);
      Params.Style := Params.Style and not (WS_HSCROLL or WS_VSCROLL);
    end;

This tells the TListBox component that, when using the CreateWindow API
function to actually create the window, it'll exclude the WS_HSCROLL and
WS_VSCROLL style bits, which are the ones that control the presence of the
scroll bars.  Install the component and use it instead of the first
TListBox.

Quote
>2) use scrollbar of Listbox2 to control both  Listbox1 and  Listbox2

Have a timer on the form which periodically checks the top visible item in
Listbox2, then, if it's different, set Listbox1 to match:

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      i, j: Integer;
    begin
      i := ListBox2.Perform(LB_GETTOPINDEX, 0, 0);
      j := ListBox1.Perform(LB_GETTOPINDEX, 0, 0);
      if i <> j then
        ListBox1.Perform(LB_SETTOPINDEX, i, 0);
    end;

I find that even with an Interval of 1, there isn't any performance
degradation.

This, though, doesn't look too nice with Win98 and its (thankfully
disableable) smooth scrolling list boxes :)

Good luck,

Cameron
_______________________
cameronm...@hotmail.com

Re:Getting rid of scrollbar in Listbox


Quote
Vic /Bhaskar Beffers wrote in message <36D13832.C940...@aoeh.azu.nl> ...
>Hi,
>I have : Listbox1 and Listbox2.
>They are positioned next to eachother. They have the same number of
>items and when the user
>select an item : Listbox1.itemindex:=Listbox2.itemindex (and vice
>versa).
>No problems so far.
>But when there are more items the fit in the visible part automatically
>two scrollbars appear.
>Now I'd like to
>1) get rid of scrollbar of Listbox1
>2) use scrollbar of Listbox2 to control both  Listbox1 and  Listbox2

>any ideas on how to do this ?

>Thanks,
>Bhas

Create ScrollBox and replace both listboxes inside it. When you change
numder of items, calculate new ListBoxN.Height (something like this
   with ListBox1 do Height:=ItemsCount*ItemHeight;
   with ListBox2 do Height:=ItemsCount*ItemHeight;

Regards,
Andrey Lakhtin                  andrey_lakh...@usa.net
Ekaterinburg, Russia                        ICQ 21183246
http://www.halyava.ru/urchemcalc/resum_en.html

Re:Getting rid of scrollbar in Listbox


Quote
> Thanks Cameron,

Everything works great now !!

bye,
Bhas

Other Threads