This kind of window object allows you to display a list of strings, which are handled exactly as with a list of elements. In particular, selection is performed exactly element by element (moreover, if multiple selection is allowed, then arbitrary row elements can be selected, not necessarily following one after another. Lines in such a list are never wrapped, and if they are not included in the width of the client part control windows are displayed truncated (if you do not prohibit horizontal scrolling, then by scrolling it is possible to read the entire line).
Constructor:
NewListBox(Parent, options) - creates an object of type TControl, as usual, returning a pointer to it of type PControl. In the options, you can set the behavior and appearance for the created list:
loNoHideScroll - do not hide the selection when the window is not in focus;
loNoExtendSel - do not allow the selection of arbitrary elements, even with the loMultiSelect option (for example, by clicking the mouse while holding down <Ctrl>);
loMultiColumn - use several columns for display (to separate columns, the tabulation symbol # 9 is used in the text of elements);
loMultiSelect - multiple lines are allowed;
loNoIntegralHeight - when this option is enabled, any size of the window in height is allowed, and not only such that an integer number of lines can fit into the client part of the window;
loNoSel - does not allow line selection at all;
loSort - the list is always sorted;
loTabstops - uses tab stops to set the width of each of the columns in a multi-column list;
loNoStrings - the list is not intended for storing strings;
loNoData - a virtual list, in which the data is not stored or displayed by the window itself, but is provided by the OnDrawItem event handler. The loOwnerDrawFixed option must also be present in this case. The programmer must in his code provide storage and display of items for the virtual list, the window in this case provides only scrolling, selection of items, keyboard and other functionality. Working with virtual lists is usually speed efficient, it is recommended to use this mechanism for large lists (over 1000 items);
loOwnerDrawFixed - the list is drawn by its own OnDrawItem handler, all lines in the list have the same height (if the OnMeasureItem event is present, it is called once to set the height of all lines). Note: the presence of the OnDrawItem event handler does not yet provide the ability to programmatically render list items: it is required that the loOwnerDrawFixed or loOwnerDrawVariable option be specified when creating an object;
loOwnerDrawVariable - similar to the previous one, but if there is an OnMeasureItem event, it is called for each row to determine its height.
Among the properties, methods and events common to all visual objects with lists, only a few specific features of properties should be noted:
SelStart - index of the first selected element (may differ from CurIndex - the current element in focus);
SelLength - the number of selected elements (including in the case when the selected elements are not always adjacent);
OnChange - the event is triggered when the set of selected items in the list changes. Same as OnSelChange for listbox;
OnSelChange - fires when the selection changes, like OnChange.
LVItemHeight- this property is common for list view (general list) and list box (simple list). It allows you to set the height of an element, which is accomplished by adding a window message handler WM_MEASUREITEM.
There is also a special method for use only in lists (also in combo boxes, see the next chapter):
AddDirList(s, attrs)- adds a list of files, subdirectories, from the specified path (the path must also contain a file mask, for example, 'C: \ Temp \ *. txt'). Directory names are appended in square brackets.
There is a TKOLListBox mirror for this control in MCK. Among other properties of this component, it should be noted that there is a design-time property Items, by editing which it is possible to prepare a list of items that will be added immediately after the creation of the object in the form initialization code.