Contents Up Previous Next

wxListBox

A listbox is used to select one or more of a list of strings. The strings are displayed in a scrolling box, with the selected string(s) marked in reverse video. A listbox can be single selection (if an item is selected, the previous selection is removed) or multiple selection (clicking an item toggles the item on or off independently of other selections).

List box elements are numbered from zero. Their number is limited in some platforms (e.g. ca. 2000 on GTK).

A listbox callback gets an event wxEVT_COMMAND_LISTBOX_SELECT for single clicks, and wxEVT_COMMAND_LISTBOX_DOUBLE_CLICKED for double clicks.

Derived from

wxControlWithItems
wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<wx/listbox.h>

Window styles

wxLB_SINGLE Single-selection list.
wxLB_MULTIPLE Multiple-selection list: the user can toggle multiple items on and off.
wxLB_EXTENDED Extended-selection list: the user can select multiple items using the SHIFT key and the mouse or special key combinations.
wxLB_HSCROLL Create horizontal scrollbar if contents are too wide (Windows only).
wxLB_ALWAYS_SB Always show a vertical scrollbar.
wxLB_NEEDED_SB Only create a vertical scrollbar if needed.
wxLB_SORT The listbox contents are sorted in alphabetical order.

Note that wxLB_SINGLE, wxLB_MULTIPLE and wxLB_EXTENDED styles are mutually exclusive and you can specify at most one of them (single selection is the default).

See also window styles overview.

Event handling

EVT_LISTBOX(id, func) Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the list is selected.
EVT_LISTBOX_DCLICK(id, func) Process a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox is double-clicked.

See also

wxChoice, wxComboBox, wxListCtrl, wxCommandEvent

Members

wxListBox::wxListBox
wxListBox::~wxListBox
wxListBox::Create
wxListBox::Deselect
wxListBox::GetSelections
wxListBox::InsertItems
wxListBox::IsSelected
wxListBox::Set
wxListBox::SetFirstItem


wxListBox::wxListBox

wxListBox()

Default constructor.

wxListBox(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, int n, const wxString choices[] = NULL, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listBox")

wxListBox(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const wxArrayString& choices, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listBox")

Constructor, creating and showing a list box.

Parameters

parent

id

pos

size

n

choices

style

validator

name

See also

wxListBox::Create, wxValidator

wxPython note: The wxListBox constructor in wxPython reduces the n and choices arguments are to a single argument, which is a list of strings.

wxPerl note: In wxPerl there is just an array reference in place of n and choices.


wxListBox::~wxListBox

void ~wxListBox()

Destructor, destroying the list box.


wxListBox::Create

bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, int n, const wxString choices[] = NULL, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listBox")

bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, const wxArrayString& choices, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listBox")

Creates the listbox for two-step construction. See wxListBox::wxListBox for further details.


wxListBox::Deselect

void Deselect(int n)

Deselects an item in the list box.

Parameters

n

Remarks

This applies to multiple selection listboxes only.


wxListBox::GetSelections

int GetSelections(wxArrayInt& selections) const

Fill an array of ints with the positions of the currently selected items.

Parameters

selections

Return value

The number of selections.

Remarks

Use this with a multiple selection listbox.

See also

wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection, wxControlWithItems::SetSelection

wxPython note: The wxPython version of this method takes no parameters and returns a tuple of the selected items.

wxPerl note: In wxPerl this method takes no parameters and return the selected items as a list.


wxListBox::InsertItems

void InsertItems(int nItems, const wxString *items, int pos)

void InsertItems(const wxArrayString& nItems, int pos)

Insert the given number of strings before the specified position.

Parameters

nItems

items

pos

wxPython note: The first two parameters are collapsed into a single parameter for wxPython, which is a list of strings.

wxPerl note: In wxPerl there is just an array reference in place of nItems and items.


wxListBox::IsSelected

bool IsSelected(int n) const

Determines whether an item is selected.

Parameters

n

Return value

true if the given item is selected, false otherwise.


wxListBox::Set

void Set(int n, const wxString* choices, void **clientData = NULL)

void Set(const wxArrayString& choices, void **clientData = NULL)

Clears the list box and adds the given strings to it.

Parameters

n

choices

clientData

Remarks

You may free the array from the calling program after this function has been called.


wxListBox::SetFirstItem

void SetFirstItem(int n)

void SetFirstItem(const wxString& string)

Set the specified item to be the first visible item. Windows only.

Parameters

n

string