TListBox - Delphi Usage Examples, Tips and Tricks
List Box with Drag and Drop Exposing the OnChange Event
The standard Delphi's TListBox implementation of a list box control does not provide an event you can handle when the selected items gets changed in the list box - there's no OnChange event to handle. Here's an extemded list box implementation with drag and drop and the OnChange event.
Delete Multiple Selected Items in a TListBox Delphi Control
When MultiSelect is true, the user can select multiple items in the control, and the SelCount property indicates the number of selected items. To remove all the selected items from the list box you need to call the Delete method of the underlying TStrings object.
Display Long TListBox Delphi Items as Hints
Sometimes the data you want to display in a list is too long for the size of ListBox you can use. When this happens, you can use the simple code to display the ListBox entries as Hints when the mouse passes over the ListBox.
ListBox with a Horizontal Scroll Bar
How to add the horizontal scrool bar to a list box control.
Store a String (or an Object) Along with a String in a ListBox
There are situations when you want to display a list of strings to the user, for example in the list box control, but also have a way to store one more additional string along the one displayed to the user. What's more, you might want to store / attach more than just a "plain" string to the string, you might want to attach an object to the item (string).
Select ListBox Strings as Mouse Hovers over Items
Here's how to set the selected item in a ListBox as mouse moves over the list box.
Place a TEdit inside a TListBox to Enable Inplace Editing
By design, a TListBox component displays a collection of items (string values) in a scrollable list. Items of a ListBox cannot be edited directly from "inside" the ListBox. If you ever needed to enable inplace editing of ListBox strings, here's a trick to place an ordinary TEdit inside a ListBox.
Change the Background Color on different Lines of text in a TListBox
After dropping a TListBox on your form, you must change the Style property of the TListBox to lbOwnerDrawFixed. If you fail to change the Style property, the OnDrawItem event will never be called. Put some special code in the OnDrawItem event of your TListBox...
TListBox with Radio Buttons
The TListBox VCL component displays a collection of items in a scrollable list. The MultiSelect property determines if a user can select more than one item. Here's how to draw a radio button for each of the items in a List Box ...
Right Align Items in a TListBox
Suppose you have a ComboBox displaying currency values, or more generally numbers. Here's how to display the items in a ComboBox right-aligned...
How to Move ListBox Items with the Mouse (Drag and Drop)
Here's how to allow a user to rearrange (change item's position) the items of a ListBox using drag and drop...
Implementing OnMouseOver for Items in a TListBox, with Custom Hints
Here's how to get the caption of an item in a TComboBox as mouse hovers over an item when the ComboBox is in drop down state. Use this "trick" to get the object associated with the "pre-selected" item in a combo box, or to display a custom hint for each item, for example.
Drag from ListBox to Edit
Handle drag and drop from a list box to an edit control.
Programmatically Jump to the Last Item in the TListBox
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.
Show TListBox Items in Multiple Columns
If you want to display several items in one row, thus have multiple columns in a list box you need to set the TabWidth property and add items to theListBox in a specific way.
Incremental Search for the TListBox
Imagine a list box with a huge number of (unsorted) items. Finding the one user wants to select might turn into a nightmare. Provide the user with an option to immediately locate the item in the list box by adding incremental search functionality.