]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxComboBox}}\label{wxcombobox} |
2 | ||
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. | |
6 | ||
7 | A combobox permits a single selection only. Combobox items are numbered from zero. | |
8 | ||
fb5f907b RR |
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}. | |
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 | |
a7af285d VZ |
25 | \wxheading{Library} |
26 | ||
27 | \helpref{wxCore}{librarieslist} | |
28 | ||
a660d684 KB |
29 | \wxheading{Window styles} |
30 | ||
31 | \begin{twocollist}\itemsep=0pt | |
9c884972 | 32 | \twocolitem{\windowstyle{wxCB\_SIMPLE}}{Creates a combobox with a permanently displayed list. Windows only. } |
a660d684 | 33 | \twocolitem{\windowstyle{wxCB\_DROPDOWN}}{Creates a combobox with a drop-down list.} |
3ca6a5f0 BP |
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.} | |
a660d684 | 37 | \twocolitem{\windowstyle{wxCB\_SORT}}{Sorts the entries in the list alphabetically.} |
591087ed | 38 | \twocolitem{\windowstyle{wxTE\_PROCESS\_ENTER}}{The control will generate |
5090e3ad JS |
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.} | |
a660d684 KB |
42 | \end{twocollist} |
43 | ||
44 | See also \helpref{window styles overview}{windowstyles}. | |
45 | ||
5de76427 JS |
46 | \wxheading{Event handling} |
47 | ||
48 | \twocolwidtha{7cm} | |
49 | \begin{twocollist}\itemsep=0pt | |
50 | \twocolitem{{\bf EVT\_COMBOBOX(id, func)}}{Process a wxEVT\_COMMAND\_COMBOBOX\_SELECTED event, | |
7d8268a1 | 51 | when an item on the list is selected. Note that calling |
13bcc348 | 52 | \helpref{GetValue}{wxcomboboxgetvalue} returns the new value of selection.} |
5de76427 JS |
53 | \twocolitem{{\bf EVT\_TEXT(id, func)}}{Process a wxEVT\_COMMAND\_TEXT\_UPDATED event, |
54 | when the combobox text changes.} | |
3980000c RR |
55 | \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Process a wxEVT\_COMMAND\_TEXT\_ENTER event, |
56 | when <RETURN> is pressed in the combobox.} | |
5de76427 JS |
57 | \end{twocollist} |
58 | ||
a660d684 KB |
59 | \wxheading{See also} |
60 | ||
5de76427 JS |
61 | \helpref{wxListBox}{wxlistbox}, \helpref{wxTextCtrl}{wxtextctrl}, \helpref{wxChoice}{wxchoice}, |
62 | \rtfsp\helpref{wxCommandEvent}{wxcommandevent} | |
a660d684 KB |
63 | |
64 | \latexignore{\rtfignore{\wxheading{Members}}} | |
65 | ||
3782aa47 | 66 | |
f510b7b2 | 67 | \membersection{wxComboBox::wxComboBox}\label{wxcomboboxctor} |
a660d684 KB |
68 | |
69 | \func{}{wxComboBox}{\void} | |
70 | ||
71 | Default constructor. | |
72 | ||
eaaa6a06 | 73 | \func{}{wxComboBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp |
a660d684 | 74 | \param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp |
89971c77 | 75 | \param{int}{ n = 0}, \param{const wxString }{choices[] = NULL},\rtfsp |
eaaa6a06 | 76 | \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}} |
a660d684 | 77 | |
56b88f12 MB |
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"}} | |
82 | ||
a660d684 KB |
83 | Constructor, creating and showing a combobox. |
84 | ||
85 | \wxheading{Parameters} | |
86 | ||
87 | \docparam{parent}{Parent window. Must not be NULL.} | |
88 | ||
89 | \docparam{id}{Window identifier. A value of -1 indicates a default value.} | |
90 | ||
2b5f62a0 VZ |
91 | \docparam{value}{Initial selection string. An empty string indicates no selection.} |
92 | ||
a660d684 KB |
93 | \docparam{pos}{Window position.} |
94 | ||
95 | \docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized | |
96 | appropriately.} | |
97 | ||
98 | \docparam{n}{Number of strings with which to initialise the control.} | |
99 | ||
100 | \docparam{choices}{An array of strings with which to initialise the control.} | |
101 | ||
102 | \docparam{style}{Window style. See \helpref{wxComboBox}{wxcombobox}.} | |
103 | ||
104 | \docparam{validator}{Window validator.} | |
105 | ||
106 | \docparam{name}{Window name.} | |
107 | ||
108 | \wxheading{See also} | |
109 | ||
110 | \helpref{wxComboBox::Create}{wxcomboboxcreate}, \helpref{wxValidator}{wxvalidator} | |
111 | ||
c9110876 VS |
112 | \pythonnote{The wxComboBox constructor in wxPython reduces the {\tt n} |
113 | and {\tt choices} arguments are to a single argument, which is | |
06d20283 RD |
114 | a list of strings.} |
115 | ||
5873607e VZ |
116 | \perlnote{In wxPerl there is just an array reference in place of {\tt n} |
117 | and {\tt choices}.} | |
06d20283 | 118 | |
3782aa47 | 119 | |
f510b7b2 | 120 | \membersection{wxComboBox::\destruct{wxComboBox}}\label{wxcomboboxdtor} |
a660d684 KB |
121 | |
122 | \func{}{\destruct{wxComboBox}}{\void} | |
123 | ||
124 | Destructor, destroying the combobox. | |
125 | ||
3782aa47 | 126 | |
a660d684 KB |
127 | \membersection{wxComboBox::Create}\label{wxcomboboxcreate} |
128 | ||
eaaa6a06 | 129 | \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp |
a660d684 | 130 | \param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp |
eaaa6a06 JS |
131 | \param{int}{ n}, \param{const wxString }{choices[]},\rtfsp |
132 | \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}} | |
a660d684 | 133 | |
56b88f12 MB |
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"}} | |
138 | ||
a660d684 | 139 | Creates the combobox for two-step construction. Derived classes |
f510b7b2 | 140 | should call or replace this function. See \helpref{wxComboBox::wxComboBox}{wxcomboboxctor}\rtfsp |
a660d684 KB |
141 | for further details. |
142 | ||
3782aa47 | 143 | |
150e31d2 JS |
144 | \membersection{wxComboBox::CanCopy}\label{wxcomboboxcancopy} |
145 | ||
146 | \constfunc{bool}{CanCopy}{\void} | |
147 | ||
148 | Returns true if the combobox is editable and there is a text selection to copy to the clipboard. | |
149 | Only available on Windows. | |
150 | ||
3782aa47 | 151 | |
150e31d2 JS |
152 | \membersection{wxComboBox::CanCut}\label{wxcomboboxcancut} |
153 | ||
154 | \constfunc{bool}{CanCut}{\void} | |
155 | ||
156 | Returns true if the combobox is editable and there is a text selection to copy to the clipboard. | |
157 | Only available on Windows. | |
158 | ||
3782aa47 | 159 | |
150e31d2 JS |
160 | \membersection{wxComboBox::CanPaste}\label{wxcomboboxcanpaste} |
161 | ||
162 | \constfunc{bool}{CanPaste}{\void} | |
163 | ||
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. | |
166 | ||
3782aa47 | 167 | |
150e31d2 JS |
168 | \membersection{wxComboBox::CanRedo}\label{wxcomboboxcanredo} |
169 | ||
170 | \constfunc{bool}{CanRedo}{\void} | |
171 | ||
172 | Returns true if the combobox is editable and the last undo can be redone. | |
173 | Only available on Windows. | |
7d8268a1 | 174 | |
3782aa47 | 175 | |
150e31d2 JS |
176 | \membersection{wxComboBox::CanUndo}\label{wxcomboboxcanundo} |
177 | ||
178 | \constfunc{bool}{CanUndo}{\void} | |
179 | ||
180 | Returns true if the combobox is editable and the last edit can be undone. | |
181 | Only available on Windows. | |
7d8268a1 | 182 | |
3782aa47 | 183 | |
a660d684 KB |
184 | \membersection{wxComboBox::Copy}\label{wxcomboboxcopy} |
185 | ||
186 | \func{void}{Copy}{\void} | |
187 | ||
188 | Copies the selected text to the clipboard. | |
189 | ||
3782aa47 | 190 | |
a660d684 KB |
191 | \membersection{wxComboBox::Cut}\label{wxcomboboxcut} |
192 | ||
193 | \func{void}{Cut}{\void} | |
194 | ||
195 | Copies the selected text to the clipboard and removes the selection. | |
196 | ||
3782aa47 | 197 | |
c63312c4 VZ |
198 | \membersection{wxComboBox::GetCurrentSelection}\label{wxcomboboxgetcurrentselection} |
199 | ||
200 | \constfunc{int}{GetCurrentSelection}{\void} | |
201 | ||
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. | |
206 | ||
207 | ||
a660d684 KB |
208 | \membersection{wxComboBox::GetInsertionPoint}\label{wxcomboboxgetinsertionpoint} |
209 | ||
210 | \constfunc{long}{GetInsertionPoint}{\void} | |
211 | ||
212 | Returns the insertion point for the combobox's text field. | |
213 | ||
3782aa47 VZ |
214 | \textbf{Note:} Under wxMSW, this function always returns $0$ if the combobox |
215 | doesn't have the focus. | |
216 | ||
217 | ||
a660d684 KB |
218 | \membersection{wxComboBox::GetLastPosition}\label{wxcomboboxgetlastposition} |
219 | ||
7d8268a1 | 220 | \constfunc{virtual wxTextPos}{GetLastPosition}{\void} |
a660d684 KB |
221 | |
222 | Returns the last position in the combobox text field. | |
223 | ||
3782aa47 | 224 | |
2887cdbd VZ |
225 | \membersection{wxComboBox::GetSelection}\label{wxcomboboxgetselection} |
226 | ||
227 | \constfunc{void}{GetSelection}{\param{long *}{from}, \param{long *}{to}} | |
228 | ||
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}. | |
232 | ||
233 | Currently this method is only implemented in wxMSW and wxGTK. | |
234 | ||
235 | ||
a660d684 KB |
236 | \membersection{wxComboBox::GetValue}\label{wxcomboboxgetvalue} |
237 | ||
238 | \constfunc{wxString}{GetValue}{\void} | |
239 | ||
240 | Returns the current value in the combobox text field. | |
241 | ||
3782aa47 | 242 | |
a660d684 KB |
243 | \membersection{wxComboBox::Paste}\label{wxcomboboxpaste} |
244 | ||
245 | \func{void}{Paste}{\void} | |
246 | ||
247 | Pastes text from the clipboard to the text field. | |
248 | ||
3782aa47 | 249 | |
150e31d2 JS |
250 | \membersection{wxComboBox::Redo}\label{wxcomboboxredo} |
251 | ||
252 | \func{void}{Redo}{\void} | |
253 | ||
254 | Redoes the last undo in the text field. Windows only. | |
255 | ||
3782aa47 | 256 | |
a660d684 KB |
257 | \membersection{wxComboBox::Replace}\label{wxcomboboxreplace} |
258 | ||
eaaa6a06 | 259 | \func{void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{text}} |
a660d684 KB |
260 | |
261 | Replaces the text between two positions with the given text, in the combobox text field. | |
262 | ||
263 | \wxheading{Parameters} | |
264 | ||
265 | \docparam{from}{The first position.} | |
266 | ||
267 | \docparam{to}{The second position.} | |
268 | ||
269 | \docparam{text}{The text to insert.} | |
270 | ||
3782aa47 | 271 | |
a660d684 KB |
272 | \membersection{wxComboBox::Remove}\label{wxcomboboxremove} |
273 | ||
eaaa6a06 | 274 | \func{void}{Remove}{\param{long}{ from}, \param{long}{ to}} |
a660d684 KB |
275 | |
276 | Removes the text between the two positions in the combobox text field. | |
277 | ||
278 | \wxheading{Parameters} | |
279 | ||
280 | \docparam{from}{The first position.} | |
281 | ||
282 | \docparam{to}{The last position.} | |
283 | ||
3782aa47 | 284 | |
a660d684 KB |
285 | \membersection{wxComboBox::SetInsertionPoint}\label{wxcomboboxsetinsertionpoint} |
286 | ||
eaaa6a06 | 287 | \func{void}{SetInsertionPoint}{\param{long}{ pos}} |
a660d684 KB |
288 | |
289 | Sets the insertion point in the combobox text field. | |
290 | ||
291 | \wxheading{Parameters} | |
292 | ||
293 | \docparam{pos}{The new insertion point.} | |
294 | ||
3782aa47 | 295 | |
a660d684 KB |
296 | \membersection{wxComboBox::SetInsertionPointEnd}\label{wxcomboboxsetinsertionpointend} |
297 | ||
298 | \func{void}{SetInsertionPointEnd}{\void} | |
299 | ||
300 | Sets the insertion point at the end of the combobox text field. | |
301 | ||
3782aa47 | 302 | |
a660d684 KB |
303 | \membersection{wxComboBox::SetSelection}\label{wxcomboboxsetselection} |
304 | ||
eaaa6a06 | 305 | \func{void}{SetSelection}{\param{long}{ from}, \param{long}{ to}} |
a660d684 KB |
306 | |
307 | Selects the text between the two positions, in the combobox text field. | |
308 | ||
309 | \wxheading{Parameters} | |
310 | ||
a660d684 KB |
311 | \docparam{from}{The first position.} |
312 | ||
313 | \docparam{to}{The second position.} | |
314 | ||
bed5584e | 315 | \pythonnote{This method is called {\tt SetMark} in wxPython, {\tt SetSelection} |
7d8268a1 | 316 | name is kept for |
bed5584e | 317 | \helpref{wxControlWithItems::SetSelection}{wxcontrolwithitemssetselection}.} |
532da0d1 | 318 | |
3782aa47 | 319 | |
a660d684 KB |
320 | \membersection{wxComboBox::SetValue}\label{wxcomboboxsetvalue} |
321 | ||
322 | \func{void}{SetValue}{\param{const wxString\& }{text}} | |
323 | ||
324 | Sets the text for the combobox text field. | |
325 | ||
3ca6a5f0 BP |
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. | |
328 | ||
a660d684 KB |
329 | \wxheading{Parameters} |
330 | ||
331 | \docparam{text}{The text to set.} | |
332 | ||
3782aa47 | 333 | |
150e31d2 JS |
334 | \membersection{wxComboBox::Undo}\label{wxcomboboxundo} |
335 | ||
336 | \func{void}{Undo}{\void} | |
337 | ||
338 | Undoes the last edit in the text field. Windows only. | |
a660d684 | 339 |