Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 821
  • Last Modified:

ListBox Scroll

Besides its automatic behaviour, what command should I use to scroll content of ListBox during run-time, whenever I want? (horizontaly, verticaly)
0
bor061297
Asked:
bor061297
  • 4
  • 3
  • 2
  • +1
1 Solution
 
mikepjCommented:
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
 
kjtengCommented:
You mean u want both hori/vert scrollbars to appear as and when you need it?

0
 
bor061297Author Commented:
>>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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kjtengCommented:
I think I know how to do that.
please reject the current answer so that I can post mine
0
 
kjtengCommented:
I think I know how to do that.
please reject the current answer so that I can post mine
0
 
Edo082297Commented:
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
 
kjtengCommented:
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
 
Edo082297Commented:
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
 
bor061297Author Commented:
How to post points to EDO?
0
 
Edo082297Commented:
Hi Bor,

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

Thanks
Edo
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now