1 \section{\class{wxComboBox
}}\label{wxcombobox
}
3 A combobox is like a combination of an edit control and a listbox. It can be
4 displayed as static list with editable or read-only text field; or a drop-down list with
5 text field; or a drop-down list without a text field.
7 A combobox permits a single selection only. Combobox items are numbered from zero.
9 If you need a customized combobox, have a look at
\helpref{wxComboCtrl
}{wxcomboctrl
},
10 \helpref{wxOwnerDrawnComboBox
}{wxownerdrawncombobox
},
\helpref{wxComboPopup
}{wxcombopopup
}
11 and the ready-to-use
\helpref{wxBitmapComboBox
}{wxbitmapcombobox
}.
13 \wxheading{Derived from
}
15 \helpref{wxControlWithItems
}{wxcontrolwithitems
}\\
16 \helpref{wxControl
}{wxcontrol
}\\
17 \helpref{wxWindow
}{wxwindow
}\\
18 \helpref{wxEvtHandler
}{wxevthandler
}\\
19 \helpref{wxObject
}{wxobject
}
21 \wxheading{Include files
}
27 \helpref{wxCore
}{librarieslist
}
29 \wxheading{Window styles
}
31 \begin{twocollist
}\itemsep=
0pt
32 \twocolitem{\windowstyle{wxCB
\_SIMPLE}}{Creates a combobox with a permanently displayed list. Windows only.
}
33 \twocolitem{\windowstyle{wxCB
\_DROPDOWN}}{Creates a combobox with a drop-down list.
}
34 \twocolitem{\windowstyle{wxCB
\_READONLY}}{Same as wxCB
\_DROPDOWN but only the
35 strings specified as the combobox choices can be selected, it is impossible to
36 select (even from a program) a string which is not in the choices list.
}
37 \twocolitem{\windowstyle{wxCB
\_SORT}}{Sorts the entries in the list alphabetically.
}
38 \twocolitem{\windowstyle{wxTE
\_PROCESS\_ENTER}}{The control will generate
39 the event wxEVT
\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
40 is either processed internally by the control or used for navigation between
41 dialog controls). Windows only.
}
44 See also
\helpref{window styles overview
}{windowstyles
}.
46 \wxheading{Event handling
}
49 \begin{twocollist
}\itemsep=
0pt
50 \twocolitem{{\bf EVT
\_COMBOBOX(id, func)
}}{Process a wxEVT
\_COMMAND\_COMBOBOX\_SELECTED event,
51 when an item on the list is selected. Note that calling
52 \helpref{GetValue
}{wxcomboboxgetvalue
} returns the new value of selection.
}
53 \twocolitem{{\bf EVT
\_TEXT(id, func)
}}{Process a wxEVT
\_COMMAND\_TEXT\_UPDATED event,
54 when the combobox text changes.
}
55 \twocolitem{{\bf EVT
\_TEXT\_ENTER(id, func)
}}{Process a wxEVT
\_COMMAND\_TEXT\_ENTER event,
56 when <RETURN> is pressed in the combobox.
}
61 \helpref{wxListBox
}{wxlistbox
},
\helpref{wxTextCtrl
}{wxtextctrl
},
\helpref{wxChoice
}{wxchoice
},
62 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
64 \latexignore{\rtfignore{\wxheading{Members
}}}
67 \membersection{wxComboBox::wxComboBox
}\label{wxcomboboxctor
}
69 \func{}{wxComboBox
}{\void}
73 \func{}{wxComboBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
74 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
75 \param{int
}{ n =
0},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
76 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
78 \func{}{wxComboBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
79 \param{const wxString\&
}{value
},
\param{const wxPoint\&
}{ pos
},
\param{const wxSize\&
}{ size
},
\rtfsp
80 \param{const wxArrayString\&
}{choices
},
\rtfsp
81 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
83 Constructor, creating and showing a combobox.
85 \wxheading{Parameters
}
87 \docparam{parent
}{Parent window. Must not be NULL.
}
89 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
91 \docparam{value
}{Initial selection string. An empty string indicates no selection.
}
93 \docparam{pos
}{Window position.
}
95 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
98 \docparam{n
}{Number of strings with which to initialise the control.
}
100 \docparam{choices
}{An array of strings with which to initialise the control.
}
102 \docparam{style
}{Window style. See
\helpref{wxComboBox
}{wxcombobox
}.
}
104 \docparam{validator
}{Window validator.
}
106 \docparam{name
}{Window name.
}
110 \helpref{wxComboBox::Create
}{wxcomboboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
112 \pythonnote{The wxComboBox constructor in wxPython reduces the
{\tt n
}
113 and
{\tt choices
} arguments are to a single argument, which is
116 \perlnote{In wxPerl there is just an array reference in place of
{\tt n
}
120 \membersection{wxComboBox::
\destruct{wxComboBox
}}\label{wxcomboboxdtor
}
122 \func{}{\destruct{wxComboBox
}}{\void}
124 Destructor, destroying the combobox.
127 \membersection{wxComboBox::Create
}\label{wxcomboboxcreate
}
129 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
130 \param{const wxString\&
}{value = ``"
},
\param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
131 \param{int
}{ n
},
\param{const wxString
}{choices
[]},
\rtfsp
132 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
134 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
135 \param{const wxString\&
}{value
},
\param{const wxPoint\&
}{ pos
},
\param{const wxSize\&
}{ size
},
\rtfsp
136 \param{const wxArrayString\&
}{choices
},
\rtfsp
137 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``comboBox"
}}
139 Creates the combobox for two-step construction. Derived classes
140 should call or replace this function. See
\helpref{wxComboBox::wxComboBox
}{wxcomboboxctor
}\rtfsp
144 \membersection{wxComboBox::CanCopy
}\label{wxcomboboxcancopy
}
146 \constfunc{bool
}{CanCopy
}{\void}
148 Returns true if the combobox is editable and there is a text selection to copy to the clipboard.
149 Only available on Windows.
152 \membersection{wxComboBox::CanCut
}\label{wxcomboboxcancut
}
154 \constfunc{bool
}{CanCut
}{\void}
156 Returns true if the combobox is editable and there is a text selection to copy to the clipboard.
157 Only available on Windows.
160 \membersection{wxComboBox::CanPaste
}\label{wxcomboboxcanpaste
}
162 \constfunc{bool
}{CanPaste
}{\void}
164 Returns true if the combobox is editable and there is text on the clipboard that can be pasted into the
165 text field. Only available on Windows.
168 \membersection{wxComboBox::CanRedo
}\label{wxcomboboxcanredo
}
170 \constfunc{bool
}{CanRedo
}{\void}
172 Returns true if the combobox is editable and the last undo can be redone.
173 Only available on Windows.
176 \membersection{wxComboBox::CanUndo
}\label{wxcomboboxcanundo
}
178 \constfunc{bool
}{CanUndo
}{\void}
180 Returns true if the combobox is editable and the last edit can be undone.
181 Only available on Windows.
184 \membersection{wxComboBox::Copy
}\label{wxcomboboxcopy
}
186 \func{void
}{Copy
}{\void}
188 Copies the selected text to the clipboard.
191 \membersection{wxComboBox::Cut
}\label{wxcomboboxcut
}
193 \func{void
}{Cut
}{\void}
195 Copies the selected text to the clipboard and removes the selection.
198 \membersection{wxComboBox::GetCurrentSelection
}\label{wxcomboboxgetcurrentselection
}
200 \constfunc{int
}{GetCurrentSelection
}{\void}
202 This function does the same things as
203 \helpref{wxChoice::GetCurrentSelection
}{wxchoicegetcurrentselection
} and
204 returns the item currently selected in the dropdown list if it's open or the
205 same thing as
\helpref{GetSelection
}{wxcontrolwithitemsgetselection
} otherwise.
208 \membersection{wxComboBox::GetInsertionPoint
}\label{wxcomboboxgetinsertionpoint
}
210 \constfunc{long
}{GetInsertionPoint
}{\void}
212 Returns the insertion point for the combobox's text field.
214 \textbf{Note:
} Under wxMSW, this function always returns $
0$ if the combobox
215 doesn't have the focus.
218 \membersection{wxComboBox::GetLastPosition
}\label{wxcomboboxgetlastposition
}
220 \constfunc{virtual wxTextPos
}{GetLastPosition
}{\void}
222 Returns the last position in the combobox text field.
225 \membersection{wxComboBox::GetSelection
}\label{wxcomboboxgetselection
}
227 \constfunc{void
}{GetSelection
}{\param{long *
}{from
},
\param{long *
}{to
}}
229 This is the same as
\helpref{wxTextCtrl::GetSelection
}{wxtextctrlgetselection
}
230 for the text control which is part of the combobox. Notice that this is a
231 different method from
\helpref{wxControlWithItems::GetSelection
}{wxcontrolwithitemsgetselection
}.
233 Currently this method is only implemented in wxMSW and wxGTK.
236 \membersection{wxComboBox::GetValue
}\label{wxcomboboxgetvalue
}
238 \constfunc{wxString
}{GetValue
}{\void}
240 Returns the current value in the combobox text field.
243 \membersection{wxComboBox::Paste
}\label{wxcomboboxpaste
}
245 \func{void
}{Paste
}{\void}
247 Pastes text from the clipboard to the text field.
250 \membersection{wxComboBox::Redo
}\label{wxcomboboxredo
}
252 \func{void
}{Redo
}{\void}
254 Redoes the last undo in the text field. Windows only.
257 \membersection{wxComboBox::Replace
}\label{wxcomboboxreplace
}
259 \func{void
}{Replace
}{\param{long
}{ from
},
\param{long
}{ to
},
\param{const wxString\&
}{text
}}
261 Replaces the text between two positions with the given text, in the combobox text field.
263 \wxheading{Parameters
}
265 \docparam{from
}{The first position.
}
267 \docparam{to
}{The second position.
}
269 \docparam{text
}{The text to insert.
}
272 \membersection{wxComboBox::Remove
}\label{wxcomboboxremove
}
274 \func{void
}{Remove
}{\param{long
}{ from
},
\param{long
}{ to
}}
276 Removes the text between the two positions in the combobox text field.
278 \wxheading{Parameters
}
280 \docparam{from
}{The first position.
}
282 \docparam{to
}{The last position.
}
285 \membersection{wxComboBox::SetInsertionPoint
}\label{wxcomboboxsetinsertionpoint
}
287 \func{void
}{SetInsertionPoint
}{\param{long
}{ pos
}}
289 Sets the insertion point in the combobox text field.
291 \wxheading{Parameters
}
293 \docparam{pos
}{The new insertion point.
}
296 \membersection{wxComboBox::SetInsertionPointEnd
}\label{wxcomboboxsetinsertionpointend
}
298 \func{void
}{SetInsertionPointEnd
}{\void}
300 Sets the insertion point at the end of the combobox text field.
303 \membersection{wxComboBox::SetSelection
}\label{wxcomboboxsetselection
}
305 \func{void
}{SetSelection
}{\param{long
}{ from
},
\param{long
}{ to
}}
307 Selects the text between the two positions, in the combobox text field.
309 \wxheading{Parameters
}
311 \docparam{from
}{The first position.
}
313 \docparam{to
}{The second position.
}
315 \pythonnote{This method is called
{\tt SetMark
} in wxPython,
{\tt SetSelection
}
317 \helpref{wxControlWithItems::SetSelection
}{wxcontrolwithitemssetselection
}.
}
320 \membersection{wxComboBox::SetValue
}\label{wxcomboboxsetvalue
}
322 \func{void
}{SetValue
}{\param{const wxString\&
}{text
}}
324 Sets the text for the combobox text field.
326 {\bf NB:
} For a combobox with
{\tt wxCB
\_READONLY} style the string must be in
327 the combobox choices list, otherwise the call to SetValue() is ignored.
329 \wxheading{Parameters
}
331 \docparam{text
}{The text to set.
}
334 \membersection{wxComboBox::Undo
}\label{wxcomboboxundo
}
336 \func{void
}{Undo
}{\void}
338 Undoes the last edit in the text field. Windows only.