contents up previous next

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.

if you need a customized combobox, have a look at wxcomboctrl, wxownerdrawncombobox, wxcombopopup and the ready-to-use wxbitmapcombobox.

derived from

wxcontrolwithitems
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.
wxte_process_enter the control will generate the event wxevt_command_text_enter (otherwise pressing enter key is either processed internally by the control or used for navigation between dialog controls). windows only.

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. note that calling getvalue returns the new value of selection.
evt_text(id, func) process a wxevt_command_text_updated event, when the combobox text changes.
evt_text_enter(id, func) process a wxevt_command_text_enter event, when <return> is pressed in the combobox.

see also

wxlistbox, wxtextctrl, wxchoice, wxcommandevent

members

wxcombobox::wxcombobox
wxcombobox::~wxcombobox
wxcombobox::create
wxcombobox::cancopy
wxcombobox::cancut
wxcombobox::canpaste
wxcombobox::canredo
wxcombobox::canundo
wxcombobox::copy
wxcombobox::cut
wxcombobox::getcurrentselection
wxcombobox::getinsertionpoint
wxcombobox::getlastposition
wxcombobox::getselection
wxcombobox::getvalue
wxcombobox::paste
wxcombobox::redo
wxcombobox::replace
wxcombobox::remove
wxcombobox::setinsertionpoint
wxcombobox::setinsertionpointend
wxcombobox::setselection
wxcombobox::setvalue
wxcombobox::undo


wxcombobox::wxcombobox

wxcombobox()

default constructor.

wxcombobox(wxwindow* parent, wxwindowid id, const wxstring& value = "", const wxpoint& pos = wxdefaultposition, const wxsize& size = wxdefaultsize, int n = 0, const wxstring choices[] = null, long style = 0, const wxvalidator& validator = wxdefaultvalidator, const wxstring& name = "combobox")

wxcombobox(wxwindow* parent, wxwindowid id, const wxstring& value, const wxpoint& pos, const wxsize& size, const wxarraystring& choices, long style = 0, const wxvalidator& validator = wxdefaultvalidator, const wxstring& name = "combobox")

constructor, creating and showing a combobox.

parameters

parent

id

value

pos

size

n

choices

style

validator

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.

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


wxcombobox::~wxcombobox

~wxcombobox()

destructor, destroying 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")

bool create(wxwindow* parent, wxwindowid id, const wxstring& value, const wxpoint& pos, const wxsize& size, const wxarraystring& 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::cancopy

bool cancopy() const

returns true if the combobox is editable and there is a text selection to copy to the clipboard. only available on windows.


wxcombobox::cancut

bool cancut() const

returns true if the combobox is editable and there is a text selection to copy to the clipboard. only available on windows.


wxcombobox::canpaste

bool canpaste() const

returns true if the combobox is editable and there is text on the clipboard that can be pasted into the text field. only available on windows.


wxcombobox::canredo

bool canredo() const

returns true if the combobox is editable and the last undo can be redone. only available on windows.


wxcombobox::canundo

bool canundo() const

returns true if the combobox is editable and the last edit can be undone. only available on windows.


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::getcurrentselection

int getcurrentselection() const

this function does the same things as wxchoice::getcurrentselection and returns the item currently selected in the dropdown list if it's open or the same thing as getselection otherwise.


wxcombobox::getinsertionpoint

long getinsertionpoint() const

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

note: under wxmsw, this function always returns 0 if the combobox doesn't have the focus.


wxcombobox::getlastposition

virtual wxtextpos getlastposition() const

returns the last position in the combobox text field.


wxcombobox::getselection

void getselection(long *from, long *to) const

this is the same as wxtextctrl::getselection for the text control which is part of the combobox. notice that this is a different method from wxcontrolwithitems::getselection.

currently this method is only implemented in wxmsw and wxgtk.


wxcombobox::getvalue

wxstring getvalue() const

returns the current value in the combobox text field.


wxcombobox::paste

void paste()

pastes text from the clipboard to the text field.


wxcombobox::redo

void redo()

redoes the last undo in the text field. windows only.


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

to

text


wxcombobox::remove

void remove(long from, long to)

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

parameters

from

to


wxcombobox::setinsertionpoint

void setinsertionpoint(long pos)

sets the insertion point in the combobox text field.

parameters

pos


wxcombobox::setinsertionpointend

void setinsertionpointend()

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


wxcombobox::setselection

void setselection(long from, long to)

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

parameters

from

to

wxpython note: this method is called setmark in wxpython, setselection name is kept for wxcontrolwithitems::setselection.


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


wxcombobox::undo

void undo()

undoes the last edit in the text field. windows only.