Solved

ListBox Scroll

Posted on 1998-06-27
10
755 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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