]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/listbox.tex
0d8465cb807e533ddca65226783c4850c5926758
[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 See also \helpref{window styles overview}{windowstyles}.
43
44 \wxheading{Event handling}
45
46 \twocolwidtha{7cm}
47 \begin{twocollist}\itemsep=0pt
48 \twocolitem{{\bf EVT\_LISTBOX(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_SELECTED event,
49 when an item on the list is selected.}
50 \twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
51 when the listbox is doubleclicked.}
52 \end{twocollist}
53
54 \wxheading{See also}
55
56 \helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl},
57 \rtfsp\helpref{wxCommandEvent}{wxcommandevent}
58
59 \latexignore{\rtfignore{\wxheading{Members}}}
60
61 \membersection{wxListBox::wxListBox}\label{wxlistboxconstr}
62
63 \func{}{wxListBox}{\void}
64
65 Default constructor.
66
67 \func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
68 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
69 \param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
70 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
71
72 Constructor, creating and showing a list box.
73
74 \wxheading{Parameters}
75
76 \docparam{parent}{Parent window. Must not be NULL.}
77
78 \docparam{id}{Window identifier. A value of -1 indicates a default value.}
79
80 \docparam{pos}{Window position.}
81
82 \docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
83 appropriately.}
84
85 \docparam{n}{Number of strings with which to initialise the control.}
86
87 \docparam{choices}{An array of strings with which to initialise the control.}
88
89 \docparam{style}{Window style. See \helpref{wxListBox}{wxlistbox}.}
90
91 \docparam{validator}{Window validator.}
92
93 \docparam{name}{Window name.}
94
95 \wxheading{See also}
96
97 \helpref{wxListBox::Create}{wxlistboxcreate}, \helpref{wxValidator}{wxvalidator}
98
99 \pythonnote{The wxListBox constructor in wxPython reduces the {\tt n}
100 and {\tt choices} arguments are to a single argument, which is
101 a list of strings.}
102
103 \perlnote{In wxPerl there is just an array reference in place of {\tt n}
104 and {\tt choices}.}
105
106 \membersection{wxListBox::\destruct{wxListBox}}
107
108 \func{void}{\destruct{wxListBox}}{\void}
109
110 Destructor, destroying the list box.
111
112 \membersection{wxListBox::Append}\label{wxlistboxappend}
113
114 \func{void}{Append}{\param{const wxString\& }{ item}}
115
116 Adds the item to the end of the list box.
117
118 \func{void}{Append}{\param{const wxString\& }{ item}, \param{void* }{clientData}}
119
120 Adds the item to the end of the list box, associating the given data
121 with the item.
122
123 \wxheading{Parameters}
124
125 \docparam{item}{String to add.}
126
127 \docparam{clientData}{Client data to associate with the item.}
128
129 \membersection{wxListBox::Clear}\label{wxlistboxclear}
130
131 \func{void}{Clear}{\void}
132
133 Clears all strings from the list box.
134
135 \membersection{wxListBox::Create}\label{wxlistboxcreate}
136
137 \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
138 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
139 \param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
140 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
141
142 Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxconstr}\rtfsp
143 for further details.
144
145 \membersection{wxListBox::Delete}\label{wxlistboxdelete}
146
147 \func{void}{Delete}{\param{int}{ n}}
148
149 Deletes an item from the listbox.
150
151 \wxheading{Parameters}
152
153 \docparam{n}{The zero-based item index.}
154
155 \membersection{wxListBox::Deselect}\label{wxlistboxdeselect}
156
157 \func{void}{Deselect}{\param{int}{ n}}
158
159 Deselects an item in the list box.
160
161 \wxheading{Parameters}
162
163 \docparam{n}{The zero-based item to deselect.}
164
165 \wxheading{Remarks}
166
167 This applies to multiple selection listboxes only.
168
169 \membersection{wxListBox::FindString}\label{wxlistboxfindstring}
170
171 \func{int}{FindString}{\param{const wxString\& }{string}}
172
173 Finds an item matching the given string.
174
175 \wxheading{Parameters}
176
177 \docparam{string}{String to find.}
178
179 \wxheading{Return value}
180
181 The zero-based position of the item, or -1 if the string was not found.
182
183 \membersection{wxListBox::GetClientData}\label{wxlistboxgetclientdata}
184
185 \constfunc{void*}{GetClientData}{\param{int}{ n}}
186
187 Returns a pointer to the client data associated with the given item (if any).
188
189 \wxheading{Parameters}
190
191 \docparam{n}{The zero-based position of the item.}
192
193 \wxheading{Return value}
194
195 A pointer to the client data, or NULL if not present.
196
197 \membersection{wxListBox::GetSelection}\label{wxlistboxgetselection}
198
199 \constfunc{int}{GetSelection}{\void}
200
201 Gets the position of the selected item.
202
203 \wxheading{Return value}
204
205 The position of the current selection.
206
207 \wxheading{Remarks}
208
209 Applicable to single selection list boxes only.
210
211 \wxheading{See also}
212
213 \helpref{wxListBox::SetSelection}{wxlistboxsetselection},\rtfsp
214 \helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp
215 \helpref{wxListBox::GetSelections}{wxlistboxgetselections}
216
217 \membersection{wxListBox::GetSelections}\label{wxlistboxgetselections}
218
219 \constfunc{int}{GetSelections}{\param{wxArrayInt\& }{selections}}
220
221 Fill an array of ints with the positions of the currently selected items.
222
223 \wxheading{Parameters}
224
225 \docparam{selections}{A reference to an wxArrayInt instance that is used to store the result of the query.}
226
227 \wxheading{Return value}
228
229 The number of selections.
230
231 \wxheading{Remarks}
232
233 Use this with a multiple selection listbox.
234
235 \wxheading{See also}
236
237 \helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp
238 \helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp
239 \helpref{wxListBox::SetSelection}{wxlistboxsetselection}
240
241 \pythonnote{The wxPython version of this method takes no parameters
242 and returns a tuple of the selected items.}
243
244 \perlnote{In wxPerl this method takes no parameters and returna the
245 selected items as a list.}
246
247 \membersection{wxListBox::GetString}\label{wxlistboxgetstring}
248
249 \constfunc{wxString}{GetString}{\param{int}{ n}}
250
251 Returns the string at the given position.
252
253 \wxheading{Parameters}
254
255 \docparam{n}{The zero-based position.}
256
257 \wxheading{Return value}
258
259 The string, or an empty string if the position was invalid.
260
261 \membersection{wxListBox::GetStringSelection}\label{wxlistboxgetstringselection}
262
263 \constfunc{wxString}{GetStringSelection}{\void}
264
265 Gets the selected string - for single selection list boxes only. This
266 must be copied by the calling program if long term use is to be made of
267 it.
268
269 \wxheading{See also}
270
271 \helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp
272 \helpref{wxListBox::GetSelections}{wxlistboxgetselections},\rtfsp
273 \helpref{wxListBox::SetSelection}{wxlistboxsetselection}
274
275 \membersection{wxListBox::InsertItems}\label{wxlistboxinsertitems}
276
277 \func{void}{InsertItems}{\param{int}{ nItems}, \param{const wxString}{ items}, \param{int}{ pos}}
278
279 Insert the given number of strings before the specified position.
280
281 \wxheading{Parameters}
282
283 \docparam{nItems}{Number of items in the array {\it items}}
284
285 \docparam{items}{Labels of items to be inserted}
286
287 \docparam{pos}{Position before which to insert the items: for example, if {\it pos} is 0 the items
288 will be inserted in the beginning of the listbox}
289
290 \pythonnote{The first two parameters are collapsed into a single
291 parameter for wxPython, which is a list of strings.}
292
293 \perlnote{In wxPerl there is just an array reference in place of {\tt nItems}
294 and {\tt items}.}
295
296 \membersection{wxListBox::Number}\label{wxlistboxnumber}
297
298 \constfunc{int}{Number}{\void}
299
300 Returns the number of items in the listbox.
301
302 \membersection{wxListBox::Selected}\label{wxlistboxselected}
303
304 \constfunc{bool}{Selected}{\param{int}{ n}}
305
306 Determines whether an item is selected.
307
308 \wxheading{Parameters}
309
310 \docparam{n}{The zero-based item index.}
311
312 \wxheading{Return value}
313
314 TRUE if the given item is selected, FALSE otherwise.
315
316 \membersection{wxListBox::Set}\label{wxlistboxset}
317
318 \func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}}
319
320 Clears the list box and adds the given strings. Not implemented for GTK.
321
322 \wxheading{Parameters}
323
324 \docparam{n}{The number of strings to set.}
325
326 \docparam{choices}{An array of strings to set.}
327
328 \wxheading{Remarks}
329
330 Deallocate the array from the calling program
331 after this function has been called.
332
333 \membersection{wxListBox::SetClientData}\label{wxlistboxsetclientdata}
334
335 \func{void}{SetClientData}{\param{int}{ n}, \param{void* }{data}}
336
337 Associates the given client data pointer with the given item.
338
339 \wxheading{Parameters}
340
341 \docparam{n}{The zero-based item index.}
342
343 \docparam{data}{The client data to associate with the item.}
344
345 \membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem}
346
347 \func{void}{SetFirstItem}{\param{int}{ n}}
348
349 \func{void}{SetFirstItem}{\param{const wxString\& }{string}}
350
351 Set the specified item to be the first visible item. Windows only.
352
353 \wxheading{Parameters}
354
355 \docparam{n}{The zero-based item index.}
356
357 \docparam{string}{The string that should be visible.}
358
359 \membersection{wxListBox::SetSelection}\label{wxlistboxsetselection}
360
361 \func{void}{SetSelection}{\param{int}{ n}, \param{const bool }{select = TRUE}}
362
363 Selects or deselects the given item. This does not cause a
364 wxEVT\_COMMAND\_LISTBOX\_SELECT event to get emitted.
365
366 \wxheading{Parameters}
367
368 \docparam{n}{The zero-based item index.}
369
370 \docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.}
371
372 \membersection{wxListBox::SetString}\label{wxlistboxsetstring}
373
374 \func{void}{SetString}{\param{int}{ n}, \param{const wxString\& }{ string}}
375
376 Sets the string value of an item.
377
378 \wxheading{Parameters}
379
380 \docparam{n}{The zero-based item index.}
381
382 \docparam{string}{The string to set.}
383
384 \membersection{wxListBox::SetStringSelection}\label{wxlistboxsetstringselection}
385
386 \func{void}{SetStringSelection}{\param{const wxString\& }{ string}, \param{const bool}{ select = TRUE}}
387
388 Sets the current selection. This does not cause a
389 wxEVT\_COMMAND\_LISTBOX\_SELECT event to get emitted.
390
391 \wxheading{Parameters}
392
393 \docparam{string}{The item to select.}
394
395 \docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.}
396