TListBox

Source: source/classes/listbox.prg

Inherits from: TControl

TListBox wraps the standard Windows list box control (LISTBOX). It displays a scrollable list of items from which the user can select one or multiple entries. TListBox supports owner-drawn items with bitmaps, drag-and-drop reordering, multiple-selection modes, keyboard navigation, and item-level tooltips. It is the standard single-column list control in FiveWin.

Key DATA Members

DATATypeDescription
aItemsArrayArray of character strings displayed in the list box.
aBitmapsArrayArray of bitmap handles or resource names for owner-drawn bitmap items. Each entry corresponds to an item in aItems.
bSetGetBlockData-binding block. When evaluated with no arguments, returns the selected item value; with one argument, selects that item.
lOwnerDrawLogicalIf .T., the list box is owner-drawn, allowing custom item rendering via bDrawItem.
bDrawItemBlockCustom drawing code block for owner-drawn items: { |nItem, hDC, aRect, nState, oLbx| ... }.
lMultiSelectLogicalIf .T., multiple items can be selected at once.
lDragLogicalEnable mouse drag-and-drop reordering of list items.
bChangeBlockEvaluated when the selection changes: { |nItem, oLbx| ... }.
bValidBlockValidation block evaluated when the list box loses focus.
nAtNumericIndex of the currently selected item (1-based). 0 means no selection.

Methods

MethodDescription
New( nRow, nCol, bSetGet, aItems, nW, nH, oWnd, lMultiSel, lDrag, lOwner, oFont, bDraw, lPixel, lDesign, oIcon, cMsg, lUpdate, bChange, bValid, ... )Create a new list box. aItems is the initial item array. bSetGet binds the selected value to a variable.
Add( cItem, nAt )Add a new item. If nAt is omitted, the item is appended at the end. If specified, it is inserted at that position.
Del( nAt )Delete the item at position nAt (1-based).
Modify( cItem, nAt )Replace the item at position nAt with new text cItem.
Select( nItem )Programmatically select the item at position nItem.
SetItems( aItems )Replace all items in the list box with a new array of strings.
GetPos()Return the index of the currently selected item (1-based). Returns 0 if no item is selected.
GetSel()Return the selected item text as a string.
nCount()Return the total number of items in the list box.
Clear()Remove all items from the list box.
End()Destroy the control.

Commands: @ ... LISTBOX

@ nRow, nCol LISTBOX oLbx ;
   ITEMS aItems ;
   [ VAR uVar ] ;
   [ SIZE nW, nH ] ;
   [ OF oDlg ] ;
   [ MULTISELECT ] ;
   [ DRAG ] ;
   [ ON CHANGE bChange ] ;
   [ ON VALID bValid ] ;
   [ BITMAPS aBitmaps ] ;
   [ OWNERDRAW ]

Example: 3-Item Listbox

#include "FiveWin.ch"

function Main()

   local oWnd, oLbx, cChoice := ""

   DEFINE WINDOW oWnd TITLE "TListBox Demo" SIZE 400, 300

   @ 20, 20 LISTBOX oLbx ;
      ITEMS { "Apples", "Oranges", "Bananas" } ;
      SIZE 200, 150 OF oWnd ;
      ON CHANGE MsgInfo( "Selected: " + oLbx:GetSel() )

   @ 200, 20 BUTTON "Get Selection" SIZE 120, 30 OF oWnd ;
      ACTION MsgInfo( "Item " + Str( oLbx:GetPos() ) + ;
                      ": " + oLbx:GetSel() )

   ACTIVATE WINDOW oWnd CENTERED

return nil

Notes

See Also