ListBox

A native Win32 list box: a scrollable column of selectable string items.

Constructors

this
this(Widget parent, ListBoxSelection selection)

Create a list box as a child of parent.

Members

Functions

addItem
int addItem(string text)

Append text to the end of the list; returns the new item's index.

clear
void clear()

Remove all items (and release any retained item data; see setItemData).

getItemCount
int getItemCount()

Return the number of items in the list.

getItemData
void* getItemData(int index)

Return the opaque pointer previously stored for the item at index.

getItemText
string getItemText(int index)

Return the text of the item at index, or "" if it has none.

getPreferredSize
Size getPreferredSize()

A sensible default size for a list box.

getSelectedIndex
int getSelectedIndex()

Return the selected item's index, or -1 (LB_ERR) if none is selected.

getSelectedIndices
int[] getSelectedIndices()

Return the indices of every selected item, or null if none are selected.

insertItem
void insertItem(int index, string text)

Insert text at index, shifting later items down.

processCommand
bool processCommand(ushort code)

Route a WM_COMMAND notification. Fires onSelectionChanged on LBN_SELCHANGE and onItemActivated on LBN_DBLCLK.

processSubclassed
bool processSubclassed(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result)

Auto-select the first item when a single-select list box gains focus and nothing is selected yet, so a screen reader announces an item on tab-in. Focus messages are never consumed.

removeItem
void removeItem(int index)

Remove the item at index.

setItemData
void setItemData(int index, void* data)

Associate an opaque data pointer with the item at index.

setItemSelected
void setItemSelected(int index, bool selected)

Select or deselect the item at index.

setSelectedIndex
void setSelectedIndex(int index)

Select the item at index (pass -1 to clear the selection).

Variables

onItemActivated
Event!(int) onItemActivated;

Fired when an item is activated (double-clicked); carries its index.

onSelectionChanged
Event!(int) onSelectionChanged;

Fired when the selection changes; carries the new selected index.

Inherited Members

From Control

controlId
int controlId()

The control's command identifier (the hMenu child id at creation).

setText
void setText(string text)

Set the control's text.

getText
string getText()

Get the control's text.

setFont
void setFont(HFONT font)

Assign a font to the control and request a repaint.

getPreferredSize
Size getPreferredSize()

A reasonable default preferred size; override per control type.

processCommand
bool processCommand(ushort notificationCode)

Handle a WM_COMMAND notification routed from the parent.

processNotify
bool processNotify(NMHDR* header)

Handle a WM_NOTIFY notification routed from the parent. Return true if it was handled. The default does nothing.

subclass
void subclass()

Install a subclass window procedure so the control can intercept its own messages (for example, swallowing the Enter key in a text field). Idempotent. Subclasses override processSubclassed to do the work.

processSubclassed
bool processSubclassed(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result)

Intercept a message while subclassed. Set result and return true to consume the message; return false to let default processing continue.

Meta