Delphi's TListBox displays a collection of items in a scrollable list that users can select, add, or delete. Learn how to use the list box control in Delphi programs.
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.
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.
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.
How to add the horizontal scrool bar to a list box control.
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).
Here's how to set the selected item in a ListBox as mouse moves over the list box.
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.
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...
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 ...
Suppose you have a ComboBox displaying currency values, or more generally numbers. Here's how to display the items in a ComboBox right-aligned...
Here's how to allow a user to rearrange (change item's position) the items of a ListBox using drag and drop...
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.
Handle drag and drop from a list box to an edit control.
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.
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.
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.