]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/listbox.tex
fixed tex2rtf error
[wxWidgets.git] / docs / latex / wx / listbox.tex
1 \section{\class{wxListBox}}\label{wxlistbox}
2
3 A listbox is used to select one or more of a list of strings. The
4 strings are displayed in a scrolling box, with the selected string(s)
5 marked in reverse video. A listbox can be single selection (if an item
6 is selected, the previous selection is removed) or multiple selection
7 (clicking an item toggles the item on or off independently of other
8 selections).
9
10 List box elements are numbered from zero. Their number is limited in
11 some platforms (e.g. ca. 2000 on GTK).
12
13 A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECT for single clicks, and
14 wxEVT\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
15
16 \wxheading{Derived from}
17
18 \helpref{wxControl}{wxcontrol}\\
19 \helpref{wxWindow}{wxwindow}\\
20 \helpref{wxEvtHandler}{wxevthandler}\\
21 \helpref{wxObject}{wxobject}
22
23 \wxheading{Include files}
24
25 <wx/listbox.h>
26
27 \wxheading{Window styles}
28
29 \twocolwidtha{5cm}%
30 \begin{twocollist}\itemsep=0pt
31 \twocolitem{\windowstyle{wxLB\_SINGLE}}{Single-selection list.}
32 \twocolitem{\windowstyle{wxLB\_MULTIPLE}}{Multiple-selection list: the user can toggle multiple
33 items on and off.}
34 \twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can
35 select multiple items using the SHIFT key and the mouse or special key combinations.}
36 \twocolitem{\windowstyle{wxLB\_HSCROLL}}{Create horizontal scrollbar if contents are too wide (Windows only).}
37 \twocolitem{\windowstyle{wxLB\_ALWAYS\_SB}}{Always show a vertical scrollbar.}
38 \twocolitem{\windowstyle{wxLB\_NEEDED\_SB}}{Only create a vertical scrollbar if needed.}
39 \twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.}
40 \end{twocollist}
41
42 Note that {\tt wxLB\_SINGLE}, {\tt wxLB\_MULTIPLE} and {\tt wxLB\_EXTENDED}
43 styles are mutually exclusive and you can specify at most one of them (single
44 selection is the default).
45
46 See also \helpref{window styles overview}{windowstyles}.
47
48 \wxheading{Event handling}
49
50 \twocolwidtha{7cm}
51 \begin{twocollist}\itemsep=0pt
52 \twocolitem{{\bf EVT\_LISTBOX(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_SELECTED event,
53 when an item on the list is selected.}
54 \twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
55 when the listbox is double-clicked.}
56 \end{twocollist}
57
58 \wxheading{See also}
59
60 \helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl},
61 \rtfsp\helpref{wxCommandEvent}{wxcommandevent}
62
63 \latexignore{\rtfignore{\wxheading{Members}}}
64
65 \membersection{wxListBox::wxListBox}\label{wxlistboxconstr}
66
67 \func{}{wxListBox}{\void}
68
69 Default constructor.
70
71 \func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
72 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
73 \param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
74 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
75
76 Constructor, creating and showing a list box.
77
78 \wxheading{Parameters}
79
80 \docparam{parent}{Parent window. Must not be NULL.}
81
82 \docparam{id}{Window identifier. A value of -1 indicates a default value.}
83
84 \docparam{pos}{Window position.}
85
86 \docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
87 appropriately.}
88
89 \docparam{n}{Number of strings with which to initialise the control.}
90
91 \docparam{choices}{An array of strings with which to initialise the control.}
92
93 \docparam{style}{Window style. See \helpref{wxListBox}{wxlistbox}.}
94
95 \docparam{validator}{Window validator.}
96
97 \docparam{name}{Window name.}
98
99 \wxheading{See also}
100
101 \helpref{wxListBox::Create}{wxlistboxcreate}, \helpref{wxValidator}{wxvalidator}
102
103 \pythonnote{The wxListBox constructor in wxPython reduces the {\tt n}
104 and {\tt choices} arguments are to a single argument, which is
105 a list of strings.}
106
107 \perlnote{In wxPerl there is just an array reference in place of {\tt n}
108 and {\tt choices}.}
109
110 \membersection{wxListBox::\destruct{wxListBox}}
111
112 \func{void}{\destruct{wxListBox}}{\void}
113
114 Destructor, destroying the list box.
115
116 \membersection{wxListBox::Append}\label{wxlistboxappend}
117
118 \func{int}{Append}{\param{const wxString\& }{ item}}
119
120 Adds the item to the end of the list box.
121
122 \func{int}{Append}{\param{const wxString\& }{ item}, \param{void* }{clientData}}
123
124 Adds the item to the end of the list box, associating the given data
125 with the item.
126
127 \wxheading{Parameters}
128
129 \docparam{item}{String to add.}
130
131 \docparam{clientData}{Client data to associate with the item.}
132
133 \wxheading{Return value}
134
135 The index of the newly added item, may be different from the last one if the
136 control has {\tt wxLB\_SORT} style.
137
138 \membersection{wxListBox::Clear}\label{wxlistboxclear}
139
140 \func{void}{Clear}{\void}
141
142 Clears all strings from the list box.
143
144 \membersection{wxListBox::Create}\label{wxlistboxcreate}
145
146 \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
147 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
148 \param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
149 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
150
151 Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxconstr}\rtfsp
152 for further details.
153
154 \membersection{wxListBox::Delete}\label{wxlistboxdelete}
155
156 \func{void}{Delete}{\param{int}{ n}}
157
158 Deletes an item from the listbox.
159
160 \wxheading{Parameters}
161
162 \docparam{n}{The zero-based item index.}
163
164 \membersection{wxListBox::Deselect}\label{wxlistboxdeselect}
165
166 \func{void}{Deselect}{\param{int}{ n}}
167
168 Deselects an item in the list box.
169
170 \wxheading{Parameters}
171
172 \docparam{n}{The zero-based item to deselect.}
173
174 \wxheading{Remarks}
175
176 This applies to multiple selection listboxes only.
177
178 \membersection{wxListBox::FindString}\label{wxlistboxfindstring}
179
180 \func{int}{FindString}{\param{const wxString\& }{string}}
181
182 Finds an item matching the given string.
183
184 \wxheading{Parameters}
185
186 \docparam{string}{String to find.}
187
188 \wxheading{Return value}
189
190 The zero-based position of the item, or -1 if the string was not found.
191
192 \membersection{wxListBox::GetClientData}\label{wxlistboxgetclientdata}
193
194 \constfunc{void*}{GetClientData}{\param{int}{ n}}
195
196 Returns a pointer to the client data associated with the given item (if any).
197
198 \wxheading{Parameters}
199
200 \docparam{n}{The zero-based position of the item.}
201
202 \wxheading{Return value}
203
204 A pointer to the client data, or NULL if not present.
205
206 \membersection{wxListBox::GetCount}\label{wxlistboxgetcount}
207
208 \constfunc{int}{GetCount}{\void}
209
210 Returns the number of items in the listbox.
211
212 \membersection{wxListBox::GetSelection}\label{wxlistboxgetselection}
213
214 \constfunc{int}{GetSelection}{\void}
215
216 Gets the position of the selected item.
217
218 \wxheading{Return value}
219
220 The position of the current selection.
221
222 \wxheading{Remarks}
223
224 Applicable to single selection list boxes only.
225
226 \wxheading{See also}
227
228 \helpref{wxListBox::SetSelection}{wxlistboxsetselection},\rtfsp
229 \helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp
230 \helpref{wxListBox::GetSelections}{wxlistboxgetselections}
231
232 \membersection{wxListBox::GetSelections}\label{wxlistboxgetselections}
233
234 \constfunc{int}{GetSelections}{\param{wxArrayInt\& }{selections}}
235
236 Fill an array of ints with the positions of the currently selected items.
237
238 \wxheading{Parameters}
239
240 \docparam{selections}{A reference to an wxArrayInt instance that is used to store the result of the query.}
241
242 \wxheading{Return value}
243
244 The number of selections.
245
246 \wxheading{Remarks}
247
248 Use this with a multiple selection listbox.
249
250 \wxheading{See also}
251
252 \helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp
253 \helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp
254 \helpref{wxListBox::SetSelection}{wxlistboxsetselection}
255
256 \pythonnote{The wxPython version of this method takes no parameters
257 and returns a tuple of the selected items.}
258
259 \perlnote{In wxPerl this method takes no parameters and return the
260 selected items as a list.}
261
262 \membersection{wxListBox::GetString}\label{wxlistboxgetstring}
263
264 \constfunc{wxString}{GetString}{\param{int}{ n}}
265
266 Returns the string at the given position.
267
268 \wxheading{Parameters}
269
270 \docparam{n}{The zero-based position.}
271
272 \wxheading{Return value}
273
274 The string, or an empty string if the position was invalid.
275
276 \membersection{wxListBox::GetStringSelection}\label{wxlistboxgetstringselection}
277
278 \constfunc{wxString}{GetStringSelection}{\void}
279
280 Gets the selected string - for single selection list boxes only. This
281 must be copied by the calling program if long term use is to be made of
282 it.
283
284 \wxheading{See also}
285
286 \helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp
287 \helpref{wxListBox::GetSelections}{wxlistboxgetselections},\rtfsp
288 \helpref{wxListBox::SetSelection}{wxlistboxsetselection}
289
290 \membersection{wxListBox::InsertItems}\label{wxlistboxinsertitems}
291
292 \func{void}{InsertItems}{\param{int}{ nItems}, \param{const wxString}{ *items}, \param{int}{ pos}}
293
294 Insert the given number of strings before the specified position.
295
296 \wxheading{Parameters}
297
298 \docparam{nItems}{Number of items in the array {\it items}}
299
300 \docparam{items}{Labels of items to be inserted}
301
302 \docparam{pos}{Position before which to insert the items: for example, if {\it pos} is 0 the items
303 will be inserted in the beginning of the listbox}
304
305 \pythonnote{The first two parameters are collapsed into a single
306 parameter for wxPython, which is a list of strings.}
307
308 \perlnote{In wxPerl there is just an array reference in place of {\tt nItems}
309 and {\tt items}.}
310
311 \membersection{wxListBox::Number}\label{wxlistboxnumber}
312
313 \constfunc{int}{Number}{\void}
314
315 {\bf Obsolescence note:} This method is obsolete and was replaced with
316 \helpref{GetCount}{wxlistboxgetcount}, please use the new method in the new
317 code. This method is only available if wxWindows was compiled with
318 {\tt WXWIN\_COMPATIBILITY\_2\_2} defined and will disappear completely in
319 future versions.
320
321 Returns the number of items in the listbox.
322
323 \membersection{wxListBox::Selected}\label{wxlistboxselected}
324
325 \constfunc{bool}{Selected}{\param{int}{ n}}
326
327 Determines whether an item is selected.
328
329 \wxheading{Parameters}
330
331 \docparam{n}{The zero-based item index.}
332
333 \wxheading{Return value}
334
335 TRUE if the given item is selected, FALSE otherwise.
336
337 \membersection{wxListBox::Set}\label{wxlistboxset}
338
339 \func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
340
341 \func{void}{Set}{\param{const wxArrayString\&}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
342
343 Clears the list box and adds the given strings to it.
344
345 \wxheading{Parameters}
346
347 \docparam{n}{The number of strings to set.}
348
349 \docparam{choices}{An array of strings to set.}
350
351 \docparam{clientData}{Options array of client data pointers}
352
353 \wxheading{Remarks}
354
355 You may free the array from the calling program after this function has been
356 called.
357
358 \membersection{wxListBox::SetClientData}\label{wxlistboxsetclientdata}
359
360 \func{void}{SetClientData}{\param{int}{ n}, \param{void* }{data}}
361
362 Associates the given client data pointer with the given item.
363
364 \wxheading{Parameters}
365
366 \docparam{n}{The zero-based item index.}
367
368 \docparam{data}{The client data to associate with the item.}
369
370 \membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem}
371
372 \func{void}{SetFirstItem}{\param{int}{ n}}
373
374 \func{void}{SetFirstItem}{\param{const wxString\& }{string}}
375
376 Set the specified item to be the first visible item. Windows only.
377
378 \wxheading{Parameters}
379
380 \docparam{n}{The zero-based item index.}
381
382 \docparam{string}{The string that should be visible.}
383
384 \membersection{wxListBox::SetSelection}\label{wxlistboxsetselection}
385
386 \func{void}{SetSelection}{\param{int}{ n}, \param{const bool }{select = TRUE}}
387
388 Selects or deselects the given item. This does not cause a
389 wxEVT\_COMMAND\_LISTBOX\_SELECT event to get emitted.
390
391 \wxheading{Parameters}
392
393 \docparam{n}{The zero-based item index.}
394
395 \docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.}
396
397 \membersection{wxListBox::SetString}\label{wxlistboxsetstring}
398
399 \func{void}{SetString}{\param{int}{ n}, \param{const wxString\& }{ string}}
400
401 Sets the string value of an item.
402
403 \wxheading{Parameters}
404
405 \docparam{n}{The zero-based item index.}
406
407 \docparam{string}{The string to set.}
408
409 \membersection{wxListBox::SetStringSelection}\label{wxlistboxsetstringselection}
410
411 \func{void}{SetStringSelection}{\param{const wxString\& }{ string}, \param{const bool}{ select = TRUE}}
412
413 Sets the current selection. This does not cause a
414 wxEVT\_COMMAND\_LISTBOX\_SELECT event to get emitted.
415
416 \wxheading{Parameters}
417
418 \docparam{string}{The item to select.}
419
420 \docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.}
421