]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/combobox.tex
Further version changes
[wxWidgets.git] / docs / latex / wx / combobox.tex
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
17 \wxheading{Include files}
18
19 <wx/combobox.h>
20
21 \wxheading{Window styles}
22
23 \begin{twocollist}\itemsep=0pt
24 \twocolitem{\windowstyle{wxCB\_SIMPLE}}{Creates a combobox with a permanently displayed list. Windows only. }
25 \twocolitem{\windowstyle{wxCB\_DROPDOWN}}{Creates a combobox with a drop-down list.}
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.}
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
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
44 \wxheading{See also}
45
46 \helpref{wxListBox}{wxlistbox}, \helpref{wxTextCtrl}{wxtextctrl}, \helpref{wxChoice}{wxchoice},
47 \rtfsp\helpref{wxCommandEvent}{wxcommandevent}
48
49 \latexignore{\rtfignore{\wxheading{Members}}}
50
51 \membersection{wxComboBox::wxComboBox}\label{wxcomboboxconstr}
52
53 \func{}{wxComboBox}{\void}
54
55 Default constructor.
56
57 \func{}{wxComboBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
58 \param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
59 \param{int}{ n}, \param{const wxString }{choices[]},\rtfsp
60 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboBox"}}
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
70 \docparam{value}{Initial selection string. An empty string indicates no selection.}
71
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
91 \pythonnote{The wxComboBox constructor in wxPython reduces the {\tt n}
92 and {\tt choices} arguments are to a single argument, which is
93 a list of strings.}
94
95 \perlnote{In wxPerl there is just an array reference in place of {\tt n}
96 and {\tt choices}.}
97
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
106 \func{void}{Append}{\param{const wxString\& }{item}}
107
108 Adds the item to the end of the combobox.
109
110 \func{void}{Append}{\param{const wxString\& }{ item}, \param{void* }{clientData}}
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
121 \membersection{wxComboBox::Clear}\label{wxcomboboxclear}
122
123 \func{void}{Clear}{\void}
124
125 Clears all strings from the combobox.
126
127 \membersection{wxComboBox::Create}\label{wxcomboboxcreate}
128
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"}}
133
134 Creates the combobox for two-step construction. Derived classes
135 should call or replace this function. See \helpref{wxComboBox::wxComboBox}{wxcomboboxconstr}\rtfsp
136 for further details.
137
138 \membersection{wxComboBox::Copy}\label{wxcomboboxcopy}
139
140 \func{void}{Copy}{\void}
141
142 Copies the selected text to the clipboard.
143
144 \membersection{wxComboBox::Cut}\label{wxcomboboxcut}
145
146 \func{void}{Cut}{\void}
147
148 Copies the selected text to the clipboard and removes the selection.
149
150 \membersection{wxComboBox::Delete}\label{wxcomboboxdelete}
151
152 \func{void}{Delete}{\param{int}{ n}}
153
154 Deletes an item from the combobox.
155
156 \wxheading{Parameters}
157
158 \docparam{n}{The item to delete, starting from zero.}
159
160 \membersection{wxComboBox::FindString}\label{wxcomboboxfindstring}
161
162 \func{int}{FindString}{\param{const wxString\& }{string}}
163
164 Finds a choice matching the given string.
165
166 \wxheading{Parameters}
167
168 \docparam{string}{The item to find.}
169
170 \wxheading{Return value}
171
172 The position if found, or -1 if not found.
173
174 \membersection{wxComboBox::GetClientData}\label{wxcomboboxgetclientdata}
175
176 \constfunc{void*}{GetClientData}{\param{int}{ n}}
177
178 Returns a pointer to the client data associated with the given item (if any).
179
180 \wxheading{Parameters}
181
182 \docparam{n}{An item, starting from zero.}
183
184 \wxheading{Return value}
185
186 A pointer to the client data, or NULL if the item was not found.
187
188 \membersection{wxComboBox::GetCount}\label{wxcomboboxgetcount}
189
190 \constfunc{int}{GetCount}{\void}
191
192 Returns the number of items in the combobox.
193
194 \membersection{wxComboBox::GetInsertionPoint}\label{wxcomboboxgetinsertionpoint}
195
196 \constfunc{long}{GetInsertionPoint}{\void}
197
198 Returns the insertion point for the combobox's text field.
199
200 \membersection{wxComboBox::GetLastPosition}\label{wxcomboboxgetlastposition}
201
202 \constfunc{long}{GetLastPosition}{\void}
203
204 Returns the last position in the combobox text field.
205
206 \membersection{wxComboBox::GetSelection}\label{wxcomboboxgetselection}
207
208 \constfunc{int}{GetSelection}{\void}
209
210 Gets the position of the selected string, or -1 if there is no selection.
211
212 \membersection{wxComboBox::GetString}\label{wxcomboboxgetstring}
213
214 \constfunc{wxString}{GetString}{\param{int}{ n}}
215
216 Returns the string at position {\it n}.
217
218 \wxheading{Parameters}
219
220 \docparam{n}{The item position, starting from zero.}
221
222 \wxheading{Return value}
223
224 The string if the item is found, otherwise the empty string.
225
226 \membersection{wxComboBox::GetStringSelection}\label{wxcomboboxgetstringselection}
227
228 \constfunc{wxString}{GetStringSelection}{\void}
229
230 Gets the selected string.
231
232 \membersection{wxComboBox::GetValue}\label{wxcomboboxgetvalue}
233
234 \constfunc{wxString}{GetValue}{\void}
235
236 Returns the current value in the combobox text field.
237
238 \membersection{wxComboBox::Number}\label{wxcomboboxnumber}
239
240 \constfunc{int}{Number}{\void}
241
242 {\bf Obsolescence note:} This method is obsolete and was replaced with
243 \helpref{GetCount}{wxcomboboxgetcount}, please use the new method in the new
244 code. This method is only available if wxWindows was compiled with
245 {\tt WXWIN\_COMPATIBILITY\_2\_2} defined and will disappear completely in
246 future versions.
247
248 Returns the number of items in the combobox list.
249
250 \membersection{wxComboBox::Paste}\label{wxcomboboxpaste}
251
252 \func{void}{Paste}{\void}
253
254 Pastes text from the clipboard to the text field.
255
256 \membersection{wxComboBox::Replace}\label{wxcomboboxreplace}
257
258 \func{void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{text}}
259
260 Replaces the text between two positions with the given text, in the combobox text field.
261
262 \wxheading{Parameters}
263
264 \docparam{from}{The first position.}
265
266 \docparam{to}{The second position.}
267
268 \docparam{text}{The text to insert.}
269
270 \membersection{wxComboBox::Remove}\label{wxcomboboxremove}
271
272 \func{void}{Remove}{\param{long}{ from}, \param{long}{ to}}
273
274 Removes the text between the two positions in the combobox text field.
275
276 \wxheading{Parameters}
277
278 \docparam{from}{The first position.}
279
280 \docparam{to}{The last position.}
281
282 \membersection{wxComboBox::SetClientData}\label{wxcomboboxsetclientdata}
283
284 \func{void}{SetClientData}{\param{int}{ n}, \param{void* }{data}}
285
286 Associates the given client data pointer with the given item.
287
288 \wxheading{Parameters}
289
290 \docparam{n}{The zero-based item.}
291
292 \docparam{data}{The client data.}
293
294 \membersection{wxComboBox::SetInsertionPoint}\label{wxcomboboxsetinsertionpoint}
295
296 \func{void}{SetInsertionPoint}{\param{long}{ pos}}
297
298 Sets the insertion point in the combobox text field.
299
300 \wxheading{Parameters}
301
302 \docparam{pos}{The new insertion point.}
303
304 \membersection{wxComboBox::SetInsertionPointEnd}\label{wxcomboboxsetinsertionpointend}
305
306 \func{void}{SetInsertionPointEnd}{\void}
307
308 Sets the insertion point at the end of the combobox text field.
309
310 \membersection{wxComboBox::SetSelection}\label{wxcomboboxsetselection}
311
312 \func{void}{SetSelection}{\param{int}{ n}}
313
314 Selects the given item in the combobox list. This does not cause a
315 wxEVT\_COMMAND\_COMBOBOX\_SELECTED event to get emitted.
316
317 \func{void}{SetSelection}{\param{long}{ from}, \param{long}{ to}}
318
319 Selects the text between the two positions, in the combobox text field.
320
321 \wxheading{Parameters}
322
323 \docparam{n}{The zero-based item to select.}
324
325 \docparam{from}{The first position.}
326
327 \docparam{to}{The second position.}
328
329 \pythonnote{The second form of this method is called {\tt SetMark} in
330 wxPython.}
331
332 \membersection{wxComboBox::SetString}\label{wxcomboboxsetstring}
333
334 \func{void}{SetString}{\param{int }{n}, \param{const wxString\& }{text}}
335
336 Replaces the specified string in the control with another one.
337
338 \wxheading{Parameters}
339
340 \docparam{n}{The zero-based index of the string to replace}
341
342 \docparam{text}{The new value for this item}
343
344 {\bf NB:} This method is currently not implemented in wxGTK.
345
346 \membersection{wxComboBox::SetValue}\label{wxcomboboxsetvalue}
347
348 \func{void}{SetValue}{\param{const wxString\& }{text}}
349
350 Sets the text for the combobox text field.
351
352 {\bf NB:} For a combobox with {\tt wxCB\_READONLY} style the string must be in
353 the combobox choices list, otherwise the call to SetValue() is ignored.
354
355 \wxheading{Parameters}
356
357 \docparam{text}{The text to set.}
358
359