## wxChoice

A choice item is used to select one of a list of strings. Unlike a listbox, only the selection is visible until the user pulls down the menu of choices.

Derived from

wxControlWithItems
wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<wx/choice.h>

Window styles

There are no special styles for wxChoice.

See also window styles overview.

Event handling

EVT_CHOICE(id, func) | Process a wxEVT_COMMAND_CHOICE_SELECTED event, when an item on the list is selected.

See also

wxListBox, wxComboBox, wxCommandEvent

Members

wxChoice::wxChoice
wxChoice::~wxChoice
wxChoice::Create
wxChoice::GetColumns
wxChoice::GetCurrentSelection
wxChoice::SetColumns

### wxChoice::wxChoice

wxChoice()

Default constructor.

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

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

Constructor, creating and showing a choice.

Parameters

parent

Parent window. Must not be NULL.

id

Window identifier. A value of -1 indicates a default value.

pos

Window position.

size

Window size. If the default size (-1, -1) is specified then the choice is sized appropriately.

n

Number of strings with which to initialise the choice control.

choices

An array of strings with which to initialise the choice control.

style

Window style. See wxChoice.

validator

Window validator.

name

Window name.

See also

wxChoice::Create, wxValidator

wxPython note: The wxChoice 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`.

### wxChoice::~wxChoice

~wxChoice()

Destructor, destroying the choice item.

### wxChoice::Create

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

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 = "choice")

Creates the choice for two-step construction. See wxChoice::wxChoice.

### wxChoice::GetColumns

int GetColumns() const

Gets the number of columns in this choice item.

Remarks

This is implemented for Motif only and always returns 1 for the other platforms.

### wxChoice::GetCurrentSelection

int GetCurrentSelection() const

Unlike GetSelection which only returns the accepted selection value, i.e. the selection in the control once the user closes the dropdown list, this function returns the current selection. That is, while the dropdown list is shown, it returns the currently selected item in it. When it is not shown, its result is the same as for the other function.

This function is new since wxWidgets version 2.6.2 (before this version GetSelection itself behaved like this).

### wxChoice::SetColumns

void SetColumns(int n = 1)

Sets the number of columns in this choice item.

Parameters

n

Number of columns.

Remarks

This is implemented for Motif only and doesn't do anything under other platforms.