Table Of Contents

Previous topic

LinuxDistributionInfo

Next topic

ListColumnFormat

This Page

phoenix_title ListBox

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 may be limited under some platforms.

A listbox callback gets an event wxEVT_COMMAND_LISTBOX_SELECTED for single clicks, and wxEVT_COMMAND_LISTBOX_DOUBLECLICKED for float clicks.

styles Window Styles

This class supports the following styles:

  • LB_SINGLE: Single-selection list.
  • LB_MULTIPLE: Multiple-selection list: the user can toggle multiple items on and off. This is the same as LB_EXTENDED in wxGTK2 port.
  • LB_EXTENDED: Extended-selection list: the user can extend the selection by using SHIFT or CTRL keys together with the cursor movement keys or the mouse.
  • LB_HSCROLL: Create horizontal scrollbar if contents are too wide (Windows only).
  • LB_ALWAYS_SB: Always show a vertical scrollbar.
  • LB_NEEDED_SB: Only create a vertical scrollbar if needed.
  • LB_NO_SB: Don’t create vertical scrollbar (wxMSW only).
  • LB_SORT: The listbox contents are sorted in alphabetical order.
Note that
LB_SINGLE , LB_MULTIPLE and LB_EXTENDED styles are mutually exclusive and you can specify at most one of them (single selection is the default). See also Window Styles.

events Events Emitted by this Class

Handlers bound for the following event types will receive a CommandEvent parameter.

  • EVT_LISTBOX: Process a wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the list is selected or the selection changes.
  • EVT_LISTBOX_DCLICK: Process a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox is double-clicked.

class_hierarchy Inheritance Diagram

Inheritance diagram for class ListBox

Inheritance diagram of ListBox


appearance Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


sub_classes Known Subclasses

CheckListBox


method_summary Methods Summary

__init__ Default constructor.
Create Creates the listbox for two-step construction.
Deselect Deselects an item in the list box.
EnsureVisible Ensure that the item with the given index is currently shown.
FindString Finds an item whose label matches the given string.
GetCount Returns the number of items in the control.
GetSelection Returns the index of the selected item or NOT_FOUND if no item is selected.
GetSelections Fill an array of ints with the positions of the currently selected items.
GetString Returns the label of the item with the given index.
HitTest Returns the item located at point, or NOT_FOUND if there is no item located at point.
InsertItems Insert the given number of strings before the specified position.
IsSelected Determines whether an item is selected.
IsSorted Return True if the listbox has LB_SORT style.
SetFirstItem Set the specified item to be the first visible item.
SetSelection Sets the selection to the given item n or removes the selection entirely if n == NOT_FOUND .
SetString Sets the label for the given item.
SetStringSelection  

api Class API



class ListBox(ControlWithItems)

A listbox is used to select one or more of a list of strings.

Possible constructors:

ListBox()

ListBox(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
        choices=[], style=0, validator=DefaultValidator,
        name=ListBoxNameStr)

Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.



__init__ (self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, choices=[], style=0, validator=DefaultValidator, name=ListBoxNameStr)

Constructor, creating and showing a list box.

See the other ListBox constructor; the only difference is that this overload takes a ArrayString instead of a pointer to an array of String.

Parameters:
  • parent (Window) –
  • id (int) –
  • pos (Point) –
  • size (Size) –
  • choices (list of strings) –
  • style (long) –
  • validator (Validator) –
  • name (string) –





Create(self, *args, **kw)

Creates the listbox for two-step construction.

See ListBox for further details.



Deselect(self, n)

Deselects an item in the list box.

Parameters:n (int) – The zero-based item to deselect.

Note

This applies to multiple selection listboxes only.



EnsureVisible(self, n)

Ensure that the item with the given index is currently shown.

Scroll the listbox if necessary.

This method is currently only implemented in wxGTK and wxOSX and does nothing in other ports.

Parameters:n (int) –

See also

SetFirstItem



FindString(self, string, caseSensitive=False)

Finds an item whose label matches the given string.

Parameters:
  • string (string) – String to find.
  • caseSensitive (bool) – Whether search is case sensitive (default is not).
Return type:

int

Returns:

The zero-based position of the item, or NOT_FOUND if the string was not found.



GetCount(self)

Returns the number of items in the control.

Return type:int

See also

IsEmpty



GetSelection(self)

Returns the index of the selected item or NOT_FOUND if no item is selected.

Return type:int
Returns:The position of the current selection.

Note

This method can be used with single selection list boxes only, you should use ListBox.GetSelections for the list boxes with LB_MULTIPLE style.

See also

SetSelection , GetStringSelection



GetSelections(self)

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

A reference to an ArrayInt instance that is used to store the result of the query.

Return type:list of integers
Returns:The number of selections.

Note

Use this with a multiple selection listbox.

See also

ControlWithItems.GetSelection , ControlWithItems.GetStringSelection , ControlWithItems.SetSelection



GetString(self, n)

Returns the label of the item with the given index.

Parameters:n (int) – The zero-based index.
Return type:string
Returns:The label of the item or an empty string if the position was invalid.


HitTest(self, *args, **kw)

overload Overloaded Implementations:



HitTest (self, point)

Returns the item located at point, or NOT_FOUND if there is no item located at point.

It is currently implemented for wxMSW, Mac and wxGTK2 ports.

Parameters:point (Point) – Point of item (in client coordinates) to obtain
Return type:int
Returns:Item located at point, or NOT_FOUND if unimplemented or the item does not exist.

New in version 2.7.0.



HitTest (self, x, y)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • x (int) –
  • y (int) –
Return type:

int





InsertItems(self, *args, **kw)

Insert the given number of strings before the specified position.

Parameters:
  • items (list of strings) – Labels of items to be inserted
  • pos (int) – Position before which to insert the items: if pos is 0 the items will be inserted in the beginning of the listbox


IsSelected(self, n)

Determines whether an item is selected.

Parameters:n (int) – The zero-based item index.
Return type:bool
Returns:True if the given item is selected, False otherwise.


IsSorted(self)

Return True if the listbox has LB_SORT style.

This method is mostly meant for internal use only.

Return type:bool


SetFirstItem(self, *args, **kw)

overload Overloaded Implementations:



SetFirstItem (self, n)

Set the specified item to be the first visible item.

Parameters:n (int) – The zero-based item index that should be visible.



SetFirstItem (self, string)

Set the specified item to be the first visible item.

Parameters:string (string) – The string that should be visible.





SetSelection(self, n)

Sets the selection to the given item n or removes the selection entirely if n == NOT_FOUND .

Note that this does not cause any command events to be emitted nor does it deselect any other items in the controls which support multiple selections.

Parameters:n (int) – The string position to select, starting from zero.


SetString(self, n, string)

Sets the label for the given item.

Parameters:
  • n (int) – The zero-based item index.
  • string (string) – The label to set.


SetStringSelection(self, *args, **kw)

overload Overloaded Implementations:



SetStringSelection (self, s, select)

Parameters:
  • s (string) –
  • select (bool) –
Return type:

bool



SetStringSelection (self, string)

Selects the item with the specified string in the control.

This method doesn’t cause any command events to be emitted.

Notice that this method is case-insensitive, i.e. the string is compared with all the elements of the control case-insensitively and the first matching entry is selected, even if it doesn’t have exactly the same case as this string and there is an exact match afterwards.

Parameters:string (string) – The string to select.
Return type:bool
Returns:True if the specified string has been selected, False if it wasn’t found in the control.




Properties



Count

See GetCount



Selection

See GetSelection and SetSelection



Selections

See GetSelections