Solved

ListBox Scroll

Posted on 1998-06-27
10
782 Views
Last Modified: 2010-04-04
Besides its automatic behaviour, what command should I use to scroll content of ListBox during run-time, whenever I want? (horizontaly, verticaly)
0
Comment
Question by:bor061297
[X]
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
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:mikepj
ID: 1356027
ListBox.TopIndex:=whatever
I don't know how to do the horizontal scrolling of a listbox but there must be a way.  Besides, I don't know why you would want to be able to do that programmatically.
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1356028
You mean u want both hori/vert scrollbars to appear as and when you need it?

0
 

Author Comment

by:bor061297
ID: 1356029
>>I don't know how to do the horizontal scrolling of a listbox
>> but there must be a way.  Besides, I don't know why you would >>want to be
>>able to do that programmatically.

I want to make a ListBox that allows user to scrool it left/right with CTRL+ LEFT/RIGHT CRSR
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:kjteng
ID: 1356030
I think I know how to do that.
please reject the current answer so that I can post mine
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1356031
I think I know how to do that.
please reject the current answer so that I can post mine
0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1356032
Delphi's TListBox component automatically implements a vertical scrollbar. The scrollbar appears when the list box isn't tall enough to display all its items. However, the list box doesn't display a horizontal scrollbar when its items are wider than its width. Of course, there's a way for you to add the horizontal scrollbar.

Add the following code to the OnCreate event of your form:

procedure TForm1.FormCreate(Sender: TObject);
var
  i, MaxWidth: integer;
begin
  MaxWidth := 0;
  for i := 0 to ListBox1.Items.Count - 1 do
    if MaxWidth < ListBox1.Canvas.TextWidth (ListBox1.Items.Strings[i]) then
      MaxWidth := ListBox1.Canvas.TextWidth(ListBox1.Items.Strings[i]);
  SendMessage(ListBox1.Handle, LB_SETHORIZONTALEXTENT, MaxWidth+2, 0);
end;

The code finds the width, in pixels, of the longest string in the list box. Then, it uses the LB_SETHORIZONTALEXTENT message to set the horizontal scrollable width, in pixels, of the list box. The two extra pixels added to MaxWidth help offset narrow characters from the right edge of the list box.

If you want to set a scroll bar to a particular line:

  SelStart := Perform( EM_LINEINDEX, LineNumber, 0 );
  Perform( EM_SCROLLCARET, 0, 0 );

If you look up the EM_ functions you'll find everything you need for concise control of your listbox scrollbars.

HTH

Edo

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1356033
use the sendMessage as follows (w is the width to scroll in pixels):
sendMessage( listbox1.handle, lb_sethorizontalExtent, w ,0)

My answer is similar to that of Edo. Since he has posted the comment, he should get the points.


0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1356034
Thanks, kjetng.

Bor, if you want some help key trapping the ctrl-left and right, just let us know, it is fairly straight forward.

Edo
0
 

Author Comment

by:bor061297
ID: 1356035
How to post points to EDO?
0
 
LVL 1

Accepted Solution

by:
Edo082297 earned 50 total points
ID: 1356036
Hi Bor,

   I hope this is OK! If you want more info, just let me know :)

Thanks
Edo
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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