## wxComboBox

A combobox is like a combination of an edit control and a listbox. It can be displayed as static list with editable or read-only text field; or a drop-down list with text field; or a drop-down list without a text field.

A combobox permits a single selection only. Combobox items are numbered from zero.

Derived from

wxChoice
wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<wx/combobox.h>

Window styles

wxCB_SIMPLE | Creates a combobox with a permanently displayed list. Windows only.
wxCB_DROPDOWN | Creates a combobox with a drop-down list.
wxCB_READONLY | Same as wxCB_DROPDOWN but only the strings specified as the combobox choices can be selected, it is impossible to select (even from a program) a string which is not in the choices list.
wxCB_SORT | Sorts the entries in the list alphabetically.

See also window styles overview.

Event handling

EVT_COMBOBOX(id, func) | Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on the list is selected.
EVT_TEXT(id, func) | Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text changes.

See also

wxListBox, wxTextCtrl, wxChoice, wxCommandEvent

Members

wxComboBox::wxComboBox
wxComboBox::~wxComboBox
wxComboBox::Append
wxComboBox::Clear
wxComboBox::Create
wxComboBox::Copy
wxComboBox::Cut
wxComboBox::Delete
wxComboBox::FindString
wxComboBox::GetClientData
wxComboBox::GetInsertionPoint
wxComboBox::GetLastPosition
wxComboBox::GetSelection
wxComboBox::GetString
wxComboBox::GetStringSelection
wxComboBox::GetValue
wxComboBox::Number
wxComboBox::Paste
wxComboBox::Replace
wxComboBox::Remove
wxComboBox::SetClientData
wxComboBox::SetInsertionPoint
wxComboBox::SetInsertionPointEnd
wxComboBox::SetSelection
wxComboBox::SetValue

### wxComboBox::wxComboBox

wxComboBox()

Default constructor.

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

Constructor, creating and showing a combobox.

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 window is sized appropriately.

n

Number of strings with which to initialise the control.

choices

An array of strings with which to initialise the control.

style

Window style. See wxComboBox.

validator

Window validator.

name

Window name.

See also

wxComboBox::Create, wxValidator

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

### wxComboBox::~wxComboBox

~wxComboBox()

Destructor, destroying the combobox.

### wxComboBox::Append

void Append(const wxString& item)

Adds the item to the end of the combobox.

void Append(const wxString& item, void* clientData)

Adds the item to the end of the combobox, associating the given data with the item.

Parameters

item

The string to add.

clientData

Client data to associate with the item.

### wxComboBox::Clear

void Clear()

Clears all strings from the combobox.

### wxComboBox::Create

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

Creates the combobox for two-step construction. Derived classes should call or replace this function. See wxComboBox::wxComboBox for further details.

### wxComboBox::Copy

void Copy()

Copies the selected text to the clipboard.

### wxComboBox::Cut

void Cut()

Copies the selected text to the clipboard and removes the selection.

### wxComboBox::Delete

void Delete(int n)

Deletes an item from the combobox.

Parameters

n

The item to delete, starting from zero.

### wxComboBox::FindString

int FindString(const wxString& string)

Finds a choice matching the given string.

Parameters

string

The item to find.

Return value

The position if found, or -1 if not found.

### wxComboBox::GetClientData

void* GetClientData(int n) const

Returns a pointer to the client data associated with the given item (if any).

Parameters

n

An item, starting from zero.

Return value

A pointer to the client data, or NULL if the item was not found.

### wxComboBox::GetInsertionPoint

long GetInsertionPoint() const

Returns the insertion point for the combobox's text field.

### wxComboBox::GetLastPosition

long GetLastPosition() const

Returns the last position in the combobox text field.

### wxComboBox::GetSelection

int GetSelection() const

Gets the position of the selected string, or -1 if there is no selection.

### wxComboBox::GetString

wxString GetString(int n) const

Returns the string at position n.

Parameters

n

The item position, starting from zero.

Return value

The string if the item is found, otherwise the empty string.

### wxComboBox::GetStringSelection

wxString GetStringSelection() const

Gets the selected string.

### wxComboBox::GetValue

wxString GetValue() const

Returns the current value in the combobox text field.

### wxComboBox::Number

int Number() const

Returns the number of items in the combobox list.

### wxComboBox::Paste

void Paste()

Pastes text from the clipboard to the text field.

### wxComboBox::Replace

void Replace(long from, long to, const wxString& text)

Replaces the text between two positions with the given text, in the combobox text field.

Parameters

from

The first position.

to

The second position.

text

The text to insert.

### wxComboBox::Remove

void Remove(long from, long to)

Removes the text between the two positions in the combobox text field.

Parameters

from

The first position.

to

The last position.

### wxComboBox::SetClientData

void SetClientData(int n, void* data)

Associates the given client data pointer with the given item.

Parameters

n

The zero-based item.

data

The client data.

### wxComboBox::SetInsertionPoint

void SetInsertionPoint(long pos)

Sets the insertion point in the combobox text field.

Parameters

pos

The new insertion point.

### wxComboBox::SetInsertionPointEnd

void SetInsertionPointEnd()

Sets the insertion point at the end of the combobox text field.

### wxComboBox::SetSelection

void SetSelection(int n)

Selects the given item in the combobox list. This does not cause a wxEVT_COMMAND_COMBOBOX_SELECTED event to get emitted.

void SetSelection(long from, long to)

Selects the text between the two positions, in the combobox text field.

Parameters

n

The zero-based item to select.

from

The first position.

to

The second position.

wxPython note: The second form of this method is called `SetMark` in wxPython.

### wxComboBox::SetValue

void SetValue(const wxString& text)

Sets the text for the combobox text field.

NB: For a combobox with `wxCB_READONLY` style the string must be in the combobox choices list, otherwise the call to SetValue() is ignored.

Parameters

text

The text to set.