]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/combobox.tex
On Mac, when selection is drawn in grey (i.e. unfocused), text color needs to be...
[wxWidgets.git] / docs / latex / wx / combobox.tex
CommitLineData
a660d684
KB
1\section{\class{wxComboBox}}\label{wxcombobox}
2
3A combobox is like a combination of an edit control and a listbox. It can be
4displayed as static list with editable or read-only text field; or a drop-down list with
5text field; or a drop-down list without a text field.
6
7A combobox permits a single selection only. Combobox items are numbered from zero.
8
fb5f907b
RR
9If you need a customized combobox, have a look at \helpref{wxComboCtrl}{wxcomboctrl},
10\helpref{wxOwnerDrawnComboBox}{wxownerdrawncombobox}, \helpref{wxComboPopup}{wxcombopopup}
11and the ready-to-use \helpref{wxBitmapComboBox}{wxbitmapcombobox}.
12
a660d684
KB
13\wxheading{Derived from}
14
bed5584e 15\helpref{wxControlWithItems}{wxcontrolwithitems}\\
a660d684
KB
16\helpref{wxControl}{wxcontrol}\\
17\helpref{wxWindow}{wxwindow}\\
18\helpref{wxEvtHandler}{wxevthandler}\\
19\helpref{wxObject}{wxobject}
20
954b8ae6
JS
21\wxheading{Include files}
22
f6bcfd97 23<wx/combobox.h>
954b8ae6 24
a660d684
KB
25\wxheading{Window styles}
26
27\begin{twocollist}\itemsep=0pt
9c884972 28\twocolitem{\windowstyle{wxCB\_SIMPLE}}{Creates a combobox with a permanently displayed list. Windows only. }
a660d684 29\twocolitem{\windowstyle{wxCB\_DROPDOWN}}{Creates a combobox with a drop-down list.}
3ca6a5f0
BP
30\twocolitem{\windowstyle{wxCB\_READONLY}}{Same as wxCB\_DROPDOWN but only the
31strings specified as the combobox choices can be selected, it is impossible to
32select (even from a program) a string which is not in the choices list.}
a660d684 33\twocolitem{\windowstyle{wxCB\_SORT}}{Sorts the entries in the list alphabetically.}
591087ed 34\twocolitem{\windowstyle{wxTE\_PROCESS\_ENTER}}{The control will generate
5090e3ad
JS
35the event wxEVT\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
36is either processed internally by the control or used for navigation between
37dialog controls). Windows only.}
a660d684
KB
38\end{twocollist}
39
40See also \helpref{window styles overview}{windowstyles}.
41
5de76427
JS
42\wxheading{Event handling}
43
44\twocolwidtha{7cm}
45\begin{twocollist}\itemsep=0pt
46\twocolitem{{\bf EVT\_COMBOBOX(id, func)}}{Process a wxEVT\_COMMAND\_COMBOBOX\_SELECTED event,
7d8268a1 47when an item on the list is selected. Note that calling
13bcc348 48\helpref{GetValue}{wxcomboboxgetvalue} returns the new value of selection.}
5de76427
JS
49\twocolitem{{\bf EVT\_TEXT(id, func)}}{Process a wxEVT\_COMMAND\_TEXT\_UPDATED event,
50when the combobox text changes.}
3980000c
RR
51\twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Process a wxEVT\_COMMAND\_TEXT\_ENTER event,
52when <RETURN> is pressed in the combobox.}
5de76427
JS
53\end{twocollist}
54
a660d684
KB
55\wxheading{See also}
56
5de76427
JS
57\helpref{wxListBox}{wxlistbox}, \helpref{wxTextCtrl}{wxtextctrl}, \helpref{wxChoice}{wxchoice},
58\rtfsp\helpref{wxCommandEvent}{wxcommandevent}
a660d684
KB
59
60\latexignore{\rtfignore{\wxheading{Members}}}
61
3782aa47 62
f510b7b2 63\membersection{wxComboBox::wxComboBox}\label{wxcomboboxctor}
a660d684
KB
64
65\func{}{wxComboBox}{\void}
66
67Default constructor.
68
eaaa6a06 69\func{}{wxComboBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 70\param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
89971c77 71\param{int}{ n = 0}, \param{const wxString }{choices[] = NULL},\rtfsp
eaaa6a06 72\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}}
a660d684 73
56b88f12
MB
74\func{}{wxComboBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
75\param{const wxString\& }{value}, \param{const wxPoint\&}{ pos}, \param{const wxSize\&}{ size},\rtfsp
76\param{const wxArrayString\& }{choices},\rtfsp
77\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}}
78
a660d684
KB
79Constructor, creating and showing a combobox.
80
81\wxheading{Parameters}
82
83\docparam{parent}{Parent window. Must not be NULL.}
84
85\docparam{id}{Window identifier. A value of -1 indicates a default value.}
86
2b5f62a0
VZ
87\docparam{value}{Initial selection string. An empty string indicates no selection.}
88
a660d684
KB
89\docparam{pos}{Window position.}
90
91\docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
92appropriately.}
93
94\docparam{n}{Number of strings with which to initialise the control.}
95
96\docparam{choices}{An array of strings with which to initialise the control.}
97
98\docparam{style}{Window style. See \helpref{wxComboBox}{wxcombobox}.}
99
100\docparam{validator}{Window validator.}
101
102\docparam{name}{Window name.}
103
104\wxheading{See also}
105
106\helpref{wxComboBox::Create}{wxcomboboxcreate}, \helpref{wxValidator}{wxvalidator}
107
c9110876
VS
108\pythonnote{The wxComboBox constructor in wxPython reduces the {\tt n}
109and {\tt choices} arguments are to a single argument, which is
06d20283
RD
110a list of strings.}
111
5873607e
VZ
112\perlnote{In wxPerl there is just an array reference in place of {\tt n}
113and {\tt choices}.}
06d20283 114
3782aa47 115
f510b7b2 116\membersection{wxComboBox::\destruct{wxComboBox}}\label{wxcomboboxdtor}
a660d684
KB
117
118\func{}{\destruct{wxComboBox}}{\void}
119
120Destructor, destroying the combobox.
121
3782aa47 122
a660d684
KB
123\membersection{wxComboBox::Create}\label{wxcomboboxcreate}
124
eaaa6a06 125\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 126\param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
127\param{int}{ n}, \param{const wxString }{choices[]},\rtfsp
128\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}}
a660d684 129
56b88f12
MB
130\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
131\param{const wxString\& }{value}, \param{const wxPoint\&}{ pos}, \param{const wxSize\&}{ size},\rtfsp
132\param{const wxArrayString\& }{choices},\rtfsp
133\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}}
134
a660d684 135Creates the combobox for two-step construction. Derived classes
f510b7b2 136should call or replace this function. See \helpref{wxComboBox::wxComboBox}{wxcomboboxctor}\rtfsp
a660d684
KB
137for further details.
138
3782aa47 139
150e31d2
JS
140\membersection{wxComboBox::CanCopy}\label{wxcomboboxcancopy}
141
142\constfunc{bool}{CanCopy}{\void}
143
144Returns true if the combobox is editable and there is a text selection to copy to the clipboard.
145Only available on Windows.
146
3782aa47 147
150e31d2
JS
148\membersection{wxComboBox::CanCut}\label{wxcomboboxcancut}
149
150\constfunc{bool}{CanCut}{\void}
151
152Returns true if the combobox is editable and there is a text selection to copy to the clipboard.
153Only available on Windows.
154
3782aa47 155
150e31d2
JS
156\membersection{wxComboBox::CanPaste}\label{wxcomboboxcanpaste}
157
158\constfunc{bool}{CanPaste}{\void}
159
160Returns true if the combobox is editable and there is text on the clipboard that can be pasted into the
161text field. Only available on Windows.
162
3782aa47 163
150e31d2
JS
164\membersection{wxComboBox::CanRedo}\label{wxcomboboxcanredo}
165
166\constfunc{bool}{CanRedo}{\void}
167
168Returns true if the combobox is editable and the last undo can be redone.
169Only available on Windows.
7d8268a1 170
3782aa47 171
150e31d2
JS
172\membersection{wxComboBox::CanUndo}\label{wxcomboboxcanundo}
173
174\constfunc{bool}{CanUndo}{\void}
175
176Returns true if the combobox is editable and the last edit can be undone.
177Only available on Windows.
7d8268a1 178
3782aa47 179
a660d684
KB
180\membersection{wxComboBox::Copy}\label{wxcomboboxcopy}
181
182\func{void}{Copy}{\void}
183
184Copies the selected text to the clipboard.
185
3782aa47 186
a660d684
KB
187\membersection{wxComboBox::Cut}\label{wxcomboboxcut}
188
189\func{void}{Cut}{\void}
190
191Copies the selected text to the clipboard and removes the selection.
192
3782aa47 193
c63312c4
VZ
194\membersection{wxComboBox::GetCurrentSelection}\label{wxcomboboxgetcurrentselection}
195
196\constfunc{int}{GetCurrentSelection}{\void}
197
198This function does the same things as
199\helpref{wxChoice::GetCurrentSelection}{wxchoicegetcurrentselection} and
200returns the item currently selected in the dropdown list if it's open or the
201same thing as \helpref{GetSelection}{wxcontrolwithitemsgetselection} otherwise.
202
203
a660d684
KB
204\membersection{wxComboBox::GetInsertionPoint}\label{wxcomboboxgetinsertionpoint}
205
206\constfunc{long}{GetInsertionPoint}{\void}
207
208Returns the insertion point for the combobox's text field.
209
3782aa47
VZ
210\textbf{Note:} Under wxMSW, this function always returns $0$ if the combobox
211doesn't have the focus.
212
213
a660d684
KB
214\membersection{wxComboBox::GetLastPosition}\label{wxcomboboxgetlastposition}
215
7d8268a1 216\constfunc{virtual wxTextPos}{GetLastPosition}{\void}
a660d684
KB
217
218Returns the last position in the combobox text field.
219
3782aa47 220
a660d684
KB
221\membersection{wxComboBox::GetValue}\label{wxcomboboxgetvalue}
222
223\constfunc{wxString}{GetValue}{\void}
224
225Returns the current value in the combobox text field.
226
3782aa47 227
a660d684
KB
228\membersection{wxComboBox::Paste}\label{wxcomboboxpaste}
229
230\func{void}{Paste}{\void}
231
232Pastes text from the clipboard to the text field.
233
3782aa47 234
150e31d2
JS
235\membersection{wxComboBox::Redo}\label{wxcomboboxredo}
236
237\func{void}{Redo}{\void}
238
239Redoes the last undo in the text field. Windows only.
240
3782aa47 241
a660d684
KB
242\membersection{wxComboBox::Replace}\label{wxcomboboxreplace}
243
eaaa6a06 244\func{void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{text}}
a660d684
KB
245
246Replaces the text between two positions with the given text, in the combobox text field.
247
248\wxheading{Parameters}
249
250\docparam{from}{The first position.}
251
252\docparam{to}{The second position.}
253
254\docparam{text}{The text to insert.}
255
3782aa47 256
a660d684
KB
257\membersection{wxComboBox::Remove}\label{wxcomboboxremove}
258
eaaa6a06 259\func{void}{Remove}{\param{long}{ from}, \param{long}{ to}}
a660d684
KB
260
261Removes the text between the two positions in the combobox text field.
262
263\wxheading{Parameters}
264
265\docparam{from}{The first position.}
266
267\docparam{to}{The last position.}
268
3782aa47 269
a660d684
KB
270\membersection{wxComboBox::SetInsertionPoint}\label{wxcomboboxsetinsertionpoint}
271
eaaa6a06 272\func{void}{SetInsertionPoint}{\param{long}{ pos}}
a660d684
KB
273
274Sets the insertion point in the combobox text field.
275
276\wxheading{Parameters}
277
278\docparam{pos}{The new insertion point.}
279
3782aa47 280
a660d684
KB
281\membersection{wxComboBox::SetInsertionPointEnd}\label{wxcomboboxsetinsertionpointend}
282
283\func{void}{SetInsertionPointEnd}{\void}
284
285Sets the insertion point at the end of the combobox text field.
286
3782aa47 287
a660d684
KB
288\membersection{wxComboBox::SetSelection}\label{wxcomboboxsetselection}
289
eaaa6a06 290\func{void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
a660d684
KB
291
292Selects the text between the two positions, in the combobox text field.
293
294\wxheading{Parameters}
295
a660d684
KB
296\docparam{from}{The first position.}
297
298\docparam{to}{The second position.}
299
bed5584e 300\pythonnote{This method is called {\tt SetMark} in wxPython, {\tt SetSelection}
7d8268a1 301name is kept for
bed5584e 302\helpref{wxControlWithItems::SetSelection}{wxcontrolwithitemssetselection}.}
532da0d1 303
3782aa47 304
a660d684
KB
305\membersection{wxComboBox::SetValue}\label{wxcomboboxsetvalue}
306
307\func{void}{SetValue}{\param{const wxString\& }{text}}
308
309Sets the text for the combobox text field.
310
3ca6a5f0
BP
311{\bf NB:} For a combobox with {\tt wxCB\_READONLY} style the string must be in
312the combobox choices list, otherwise the call to SetValue() is ignored.
313
a660d684
KB
314\wxheading{Parameters}
315
316\docparam{text}{The text to set.}
317
3782aa47 318
150e31d2
JS
319\membersection{wxComboBox::Undo}\label{wxcomboboxundo}
320
321\func{void}{Undo}{\void}
322
323Undoes the last edit in the text field. Windows only.
a660d684 324