1. Home
  2. Computing & Technology
  3. Delphi Programming

How to Jump to the Last Item in the TListBox

By Zarko Gajic, About.com

The TListBox Delphi component displays a collection of items in a scrollable list.
When dynamically adding items to the ListBox you might want to ensure that the last added item is visible - so that the user does not have to use the scroll bar to move to the end of the list.

The TopIndex property determines the index number of the item that appears at the top of the list box. While you can use this handy property to get or set the first item displayed at the top of the list box, you can also use it to ensure that the last item is visible:

 ListBox1.TopIndex := -1 + ListBox1.Items.Count;
By setting TopIndex to the number of the items in the list, you are sure that the last item will be visible (as well as all the items at the end of the list that can "fit" into the box).

Delphi tips navigator:
» How to Access a TRadioButton from a TRadioGroup - Disable, Change Font, etc.
« How to Programmatically Open the Recycle Bin from Delphi Code

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TListBox
  6. How to Jump to the Last Item in the TListBox Delphi component

©2009 About.com, a part of The New York Times Company.

All rights reserved.