Solved

ListBox Scroll

Posted on 1998-06-27
10
769 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 63
tidtcpserver connection lost handle 2 111
Firemonkey android show image from resource ? 1 57
Firemonkey allowing RTL on android 6 56
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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