]>
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 | ||
9 | \wxheading{Derived from} | |
10 | ||
11 | \helpref{wxChoice}{wxchoice}\\ | |
12 | \helpref{wxControl}{wxcontrol}\\ | |
13 | \helpref{wxWindow}{wxwindow}\\ | |
14 | \helpref{wxEvtHandler}{wxevthandler}\\ | |
15 | \helpref{wxObject}{wxobject} | |
16 | ||
954b8ae6 JS |
17 | \wxheading{Include files} |
18 | ||
f6bcfd97 | 19 | <wx/combobox.h> |
954b8ae6 | 20 | |
a660d684 KB |
21 | \wxheading{Window styles} |
22 | ||
23 | \begin{twocollist}\itemsep=0pt | |
9c884972 | 24 | \twocolitem{\windowstyle{wxCB\_SIMPLE}}{Creates a combobox with a permanently displayed list. Windows only. } |
a660d684 | 25 | \twocolitem{\windowstyle{wxCB\_DROPDOWN}}{Creates a combobox with a drop-down list.} |
3ca6a5f0 BP |
26 | \twocolitem{\windowstyle{wxCB\_READONLY}}{Same as wxCB\_DROPDOWN but only the |
27 | strings specified as the combobox choices can be selected, it is impossible to | |
28 | select (even from a program) a string which is not in the choices list.} | |
a660d684 KB |
29 | \twocolitem{\windowstyle{wxCB\_SORT}}{Sorts the entries in the list alphabetically.} |
30 | \end{twocollist} | |
31 | ||
32 | See also \helpref{window styles overview}{windowstyles}. | |
33 | ||
5de76427 JS |
34 | \wxheading{Event handling} |
35 | ||
36 | \twocolwidtha{7cm} | |
37 | \begin{twocollist}\itemsep=0pt | |
38 | \twocolitem{{\bf EVT\_COMBOBOX(id, func)}}{Process a wxEVT\_COMMAND\_COMBOBOX\_SELECTED event, | |
39 | when an item on the list is selected.} | |
40 | \twocolitem{{\bf EVT\_TEXT(id, func)}}{Process a wxEVT\_COMMAND\_TEXT\_UPDATED event, | |
41 | when the combobox text changes.} | |
42 | \end{twocollist} | |
43 | ||
a660d684 KB |
44 | \wxheading{See also} |
45 | ||
5de76427 JS |
46 | \helpref{wxListBox}{wxlistbox}, \helpref{wxTextCtrl}{wxtextctrl}, \helpref{wxChoice}{wxchoice}, |
47 | \rtfsp\helpref{wxCommandEvent}{wxcommandevent} | |
a660d684 KB |
48 | |
49 | \latexignore{\rtfignore{\wxheading{Members}}} | |
50 | ||
51 | \membersection{wxComboBox::wxComboBox}\label{wxcomboboxconstr} | |
52 | ||
53 | \func{}{wxComboBox}{\void} | |
54 | ||
55 | Default constructor. | |
56 | ||
eaaa6a06 | 57 | \func{}{wxComboBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp |
a660d684 | 58 | \param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp |
eaaa6a06 JS |
59 | \param{int}{ n}, \param{const wxString }{choices[]},\rtfsp |
60 | \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}} | |
a660d684 KB |
61 | |
62 | Constructor, creating and showing a combobox. | |
63 | ||
64 | \wxheading{Parameters} | |
65 | ||
66 | \docparam{parent}{Parent window. Must not be NULL.} | |
67 | ||
68 | \docparam{id}{Window identifier. A value of -1 indicates a default value.} | |
69 | ||
2b5f62a0 VZ |
70 | \docparam{value}{Initial selection string. An empty string indicates no selection.} |
71 | ||
a660d684 KB |
72 | \docparam{pos}{Window position.} |
73 | ||
74 | \docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized | |
75 | appropriately.} | |
76 | ||
77 | \docparam{n}{Number of strings with which to initialise the control.} | |
78 | ||
79 | \docparam{choices}{An array of strings with which to initialise the control.} | |
80 | ||
81 | \docparam{style}{Window style. See \helpref{wxComboBox}{wxcombobox}.} | |
82 | ||
83 | \docparam{validator}{Window validator.} | |
84 | ||
85 | \docparam{name}{Window name.} | |
86 | ||
87 | \wxheading{See also} | |
88 | ||
89 | \helpref{wxComboBox::Create}{wxcomboboxcreate}, \helpref{wxValidator}{wxvalidator} | |
90 | ||
c9110876 VS |
91 | \pythonnote{The wxComboBox constructor in wxPython reduces the {\tt n} |
92 | and {\tt choices} arguments are to a single argument, which is | |
06d20283 RD |
93 | a list of strings.} |
94 | ||
5873607e VZ |
95 | \perlnote{In wxPerl there is just an array reference in place of {\tt n} |
96 | and {\tt choices}.} | |
06d20283 | 97 | |
a660d684 KB |
98 | \membersection{wxComboBox::\destruct{wxComboBox}} |
99 | ||
100 | \func{}{\destruct{wxComboBox}}{\void} | |
101 | ||
102 | Destructor, destroying the combobox. | |
103 | ||
104 | \membersection{wxComboBox::Append}\label{wxcomboboxappend} | |
105 | ||
801a492c | 106 | \func{int}{Append}{\param{const wxString\& }{item}} |
a660d684 KB |
107 | |
108 | Adds the item to the end of the combobox. | |
109 | ||
801a492c | 110 | \func{int}{Append}{\param{const wxString\& }{ item}, \param{void* }{clientData}} |
a660d684 KB |
111 | |
112 | Adds the item to the end of the combobox, associating the given data | |
113 | with the item. | |
114 | ||
115 | \wxheading{Parameters} | |
116 | ||
117 | \docparam{item}{The string to add.} | |
118 | ||
119 | \docparam{clientData}{Client data to associate with the item.} | |
120 | ||
801a492c VZ |
121 | \wxheading{Return value} |
122 | ||
123 | The index of the newly added item, may be different from the last one if the | |
124 | control has {\tt wxLB\_SORT} style. | |
125 | ||
a660d684 KB |
126 | \membersection{wxComboBox::Clear}\label{wxcomboboxclear} |
127 | ||
128 | \func{void}{Clear}{\void} | |
129 | ||
130 | Clears all strings from the combobox. | |
131 | ||
132 | \membersection{wxComboBox::Create}\label{wxcomboboxcreate} | |
133 | ||
eaaa6a06 | 134 | \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp |
a660d684 | 135 | \param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp |
eaaa6a06 JS |
136 | \param{int}{ n}, \param{const wxString }{choices[]},\rtfsp |
137 | \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}} | |
a660d684 KB |
138 | |
139 | Creates the combobox for two-step construction. Derived classes | |
140 | should call or replace this function. See \helpref{wxComboBox::wxComboBox}{wxcomboboxconstr}\rtfsp | |
141 | for further details. | |
142 | ||
143 | \membersection{wxComboBox::Copy}\label{wxcomboboxcopy} | |
144 | ||
145 | \func{void}{Copy}{\void} | |
146 | ||
147 | Copies the selected text to the clipboard. | |
148 | ||
149 | \membersection{wxComboBox::Cut}\label{wxcomboboxcut} | |
150 | ||
151 | \func{void}{Cut}{\void} | |
152 | ||
153 | Copies the selected text to the clipboard and removes the selection. | |
154 | ||
155 | \membersection{wxComboBox::Delete}\label{wxcomboboxdelete} | |
156 | ||
eaaa6a06 | 157 | \func{void}{Delete}{\param{int}{ n}} |
a660d684 KB |
158 | |
159 | Deletes an item from the combobox. | |
160 | ||
161 | \wxheading{Parameters} | |
162 | ||
163 | \docparam{n}{The item to delete, starting from zero.} | |
164 | ||
a660d684 KB |
165 | \membersection{wxComboBox::FindString}\label{wxcomboboxfindstring} |
166 | ||
167 | \func{int}{FindString}{\param{const wxString\& }{string}} | |
168 | ||
169 | Finds a choice matching the given string. | |
170 | ||
171 | \wxheading{Parameters} | |
172 | ||
173 | \docparam{string}{The item to find.} | |
174 | ||
175 | \wxheading{Return value} | |
176 | ||
177 | The position if found, or -1 if not found. | |
178 | ||
179 | \membersection{wxComboBox::GetClientData}\label{wxcomboboxgetclientdata} | |
180 | ||
9c884972 | 181 | \constfunc{void*}{GetClientData}{\param{int}{ n}} |
a660d684 KB |
182 | |
183 | Returns a pointer to the client data associated with the given item (if any). | |
184 | ||
185 | \wxheading{Parameters} | |
186 | ||
187 | \docparam{n}{An item, starting from zero.} | |
188 | ||
189 | \wxheading{Return value} | |
190 | ||
191 | A pointer to the client data, or NULL if the item was not found. | |
192 | ||
28ca7610 VZ |
193 | \membersection{wxComboBox::GetCount}\label{wxcomboboxgetcount} |
194 | ||
195 | \constfunc{int}{GetCount}{\void} | |
196 | ||
197 | Returns the number of items in the combobox. | |
198 | ||
a660d684 KB |
199 | \membersection{wxComboBox::GetInsertionPoint}\label{wxcomboboxgetinsertionpoint} |
200 | ||
201 | \constfunc{long}{GetInsertionPoint}{\void} | |
202 | ||
203 | Returns the insertion point for the combobox's text field. | |
204 | ||
205 | \membersection{wxComboBox::GetLastPosition}\label{wxcomboboxgetlastposition} | |
206 | ||
207 | \constfunc{long}{GetLastPosition}{\void} | |
208 | ||
209 | Returns the last position in the combobox text field. | |
210 | ||
211 | \membersection{wxComboBox::GetSelection}\label{wxcomboboxgetselection} | |
212 | ||
213 | \constfunc{int}{GetSelection}{\void} | |
214 | ||
215 | Gets the position of the selected string, or -1 if there is no selection. | |
216 | ||
217 | \membersection{wxComboBox::GetString}\label{wxcomboboxgetstring} | |
218 | ||
219 | \constfunc{wxString}{GetString}{\param{int}{ n}} | |
220 | ||
221 | Returns the string at position {\it n}. | |
222 | ||
223 | \wxheading{Parameters} | |
224 | ||
225 | \docparam{n}{The item position, starting from zero.} | |
226 | ||
227 | \wxheading{Return value} | |
228 | ||
229 | The string if the item is found, otherwise the empty string. | |
230 | ||
231 | \membersection{wxComboBox::GetStringSelection}\label{wxcomboboxgetstringselection} | |
232 | ||
233 | \constfunc{wxString}{GetStringSelection}{\void} | |
234 | ||
235 | Gets the selected string. | |
236 | ||
237 | \membersection{wxComboBox::GetValue}\label{wxcomboboxgetvalue} | |
238 | ||
239 | \constfunc{wxString}{GetValue}{\void} | |
240 | ||
241 | Returns the current value in the combobox text field. | |
242 | ||
243 | \membersection{wxComboBox::Number}\label{wxcomboboxnumber} | |
244 | ||
245 | \constfunc{int}{Number}{\void} | |
246 | ||
28ca7610 VZ |
247 | {\bf Obsolescence note:} This method is obsolete and was replaced with |
248 | \helpref{GetCount}{wxcomboboxgetcount}, please use the new method in the new | |
249 | code. This method is only available if wxWindows was compiled with | |
250 | {\tt WXWIN\_COMPATIBILITY\_2\_2} defined and will disappear completely in | |
251 | future versions. | |
252 | ||
a660d684 | 253 | Returns the number of items in the combobox list. |
a660d684 KB |
254 | |
255 | \membersection{wxComboBox::Paste}\label{wxcomboboxpaste} | |
256 | ||
257 | \func{void}{Paste}{\void} | |
258 | ||
259 | Pastes text from the clipboard to the text field. | |
260 | ||
261 | \membersection{wxComboBox::Replace}\label{wxcomboboxreplace} | |
262 | ||
eaaa6a06 | 263 | \func{void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{text}} |
a660d684 KB |
264 | |
265 | Replaces the text between two positions with the given text, in the combobox text field. | |
266 | ||
267 | \wxheading{Parameters} | |
268 | ||
269 | \docparam{from}{The first position.} | |
270 | ||
271 | \docparam{to}{The second position.} | |
272 | ||
273 | \docparam{text}{The text to insert.} | |
274 | ||
275 | \membersection{wxComboBox::Remove}\label{wxcomboboxremove} | |
276 | ||
eaaa6a06 | 277 | \func{void}{Remove}{\param{long}{ from}, \param{long}{ to}} |
a660d684 KB |
278 | |
279 | Removes the text between the two positions in the combobox text field. | |
280 | ||
281 | \wxheading{Parameters} | |
282 | ||
283 | \docparam{from}{The first position.} | |
284 | ||
285 | \docparam{to}{The last position.} | |
286 | ||
287 | \membersection{wxComboBox::SetClientData}\label{wxcomboboxsetclientdata} | |
288 | ||
9c884972 | 289 | \func{void}{SetClientData}{\param{int}{ n}, \param{void* }{data}} |
a660d684 KB |
290 | |
291 | Associates the given client data pointer with the given item. | |
292 | ||
293 | \wxheading{Parameters} | |
294 | ||
295 | \docparam{n}{The zero-based item.} | |
296 | ||
297 | \docparam{data}{The client data.} | |
298 | ||
299 | \membersection{wxComboBox::SetInsertionPoint}\label{wxcomboboxsetinsertionpoint} | |
300 | ||
eaaa6a06 | 301 | \func{void}{SetInsertionPoint}{\param{long}{ pos}} |
a660d684 KB |
302 | |
303 | Sets the insertion point in the combobox text field. | |
304 | ||
305 | \wxheading{Parameters} | |
306 | ||
307 | \docparam{pos}{The new insertion point.} | |
308 | ||
309 | \membersection{wxComboBox::SetInsertionPointEnd}\label{wxcomboboxsetinsertionpointend} | |
310 | ||
311 | \func{void}{SetInsertionPointEnd}{\void} | |
312 | ||
313 | Sets the insertion point at the end of the combobox text field. | |
314 | ||
315 | \membersection{wxComboBox::SetSelection}\label{wxcomboboxsetselection} | |
316 | ||
eaaa6a06 | 317 | \func{void}{SetSelection}{\param{int}{ n}} |
a660d684 | 318 | |
953704c1 RR |
319 | Selects the given item in the combobox list. This does not cause a |
320 | wxEVT\_COMMAND\_COMBOBOX\_SELECTED event to get emitted. | |
a660d684 | 321 | |
eaaa6a06 | 322 | \func{void}{SetSelection}{\param{long}{ from}, \param{long}{ to}} |
a660d684 KB |
323 | |
324 | Selects the text between the two positions, in the combobox text field. | |
325 | ||
326 | \wxheading{Parameters} | |
327 | ||
328 | \docparam{n}{The zero-based item to select.} | |
329 | ||
330 | \docparam{from}{The first position.} | |
331 | ||
332 | \docparam{to}{The second position.} | |
333 | ||
c9110876 | 334 | \pythonnote{The second form of this method is called {\tt SetMark} in |
a2c75a02 RD |
335 | wxPython.} |
336 | ||
532da0d1 VZ |
337 | \membersection{wxComboBox::SetString}\label{wxcomboboxsetstring} |
338 | ||
339 | \func{void}{SetString}{\param{int }{n}, \param{const wxString\& }{text}} | |
340 | ||
341 | Replaces the specified string in the control with another one. | |
342 | ||
343 | \wxheading{Parameters} | |
344 | ||
345 | \docparam{n}{The zero-based index of the string to replace} | |
346 | ||
347 | \docparam{text}{The new value for this item} | |
348 | ||
349 | {\bf NB:} This method is currently not implemented in wxGTK. | |
350 | ||
a660d684 KB |
351 | \membersection{wxComboBox::SetValue}\label{wxcomboboxsetvalue} |
352 | ||
353 | \func{void}{SetValue}{\param{const wxString\& }{text}} | |
354 | ||
355 | Sets the text for the combobox text field. | |
356 | ||
3ca6a5f0 BP |
357 | {\bf NB:} For a combobox with {\tt wxCB\_READONLY} style the string must be in |
358 | the combobox choices list, otherwise the call to SetValue() is ignored. | |
359 | ||
a660d684 KB |
360 | \wxheading{Parameters} |
361 | ||
362 | \docparam{text}{The text to set.} | |
363 | ||
364 |