]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/listbox.tex
use MoreFilesX instead of MoreFiles when building with Apple Developer Tools
[wxWidgets.git] / docs / latex / wx / listbox.tex
CommitLineData
a660d684
KB
1\section{\class{wxListBox}}\label{wxlistbox}
2
3A listbox is used to select one or more of a list of strings. The
4strings are displayed in a scrolling box, with the selected string(s)
5marked in reverse video. A listbox can be single selection (if an item
6is selected, the previous selection is removed) or multiple selection
7(clicking an item toggles the item on or off independently of other
8selections).
9
27d029c7
RR
10List box elements are numbered from zero. Their number is limited in
11some platforms (e.g. ca. 2000 on GTK).
a660d684
KB
12
13A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECT for single clicks, and
debe6624 14wxEVT\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
a660d684
KB
15
16\wxheading{Derived from}
17
18\helpref{wxControl}{wxcontrol}\\
19\helpref{wxWindow}{wxwindow}\\
20\helpref{wxEvtHandler}{wxevthandler}\\
21\helpref{wxObject}{wxobject}
22
954b8ae6
JS
23\wxheading{Include files}
24
25<wx/listbox.h>
26
a660d684
KB
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
33items on and off.}
34\twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can
35select 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.}
3377b962 39\twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.}
a660d684
KB
40\end{twocollist}
41
54081dc5
VZ
42Note that {\tt wxLB\_SINGLE}, {\tt wxLB\_MULTIPLE} and {\tt wxLB\_EXTENDED}
43styles are mutually exclusive and you can specify at most one of them (single
44selection is the default).
45
a660d684
KB
46See also \helpref{window styles overview}{windowstyles}.
47
5de76427
JS
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,
53when an item on the list is selected.}
def172b2 54\twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
2edb0bde 55when the listbox is double-clicked.}
5de76427
JS
56\end{twocollist}
57
a660d684
KB
58\wxheading{See also}
59
5de76427
JS
60\helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl},
61\rtfsp\helpref{wxCommandEvent}{wxcommandevent}
a660d684
KB
62
63\latexignore{\rtfignore{\wxheading{Members}}}
64
65\membersection{wxListBox::wxListBox}\label{wxlistboxconstr}
66
67\func{}{wxListBox}{\void}
68
69Default constructor.
70
eaaa6a06 71\func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 72\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
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"}}
a660d684
KB
75
76Constructor, 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
87appropriately.}
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
c9110876
VS
103\pythonnote{The wxListBox constructor in wxPython reduces the {\tt n}
104and {\tt choices} arguments are to a single argument, which is
06d20283
RD
105a list of strings.}
106
5873607e
VZ
107\perlnote{In wxPerl there is just an array reference in place of {\tt n}
108and {\tt choices}.}
06d20283 109
a660d684
KB
110\membersection{wxListBox::\destruct{wxListBox}}
111
112\func{void}{\destruct{wxListBox}}{\void}
113
114Destructor, destroying the list box.
115
116\membersection{wxListBox::Append}\label{wxlistboxappend}
117
801a492c 118\func{int}{Append}{\param{const wxString\& }{ item}}
a660d684
KB
119
120Adds the item to the end of the list box.
121
801a492c 122\func{int}{Append}{\param{const wxString\& }{ item}, \param{void* }{clientData}}
a660d684
KB
123
124Adds the item to the end of the list box, associating the given data
125with 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
801a492c
VZ
133\wxheading{Return value}
134
135The index of the newly added item, may be different from the last one if the
136control has {\tt wxLB\_SORT} style.
137
a660d684
KB
138\membersection{wxListBox::Clear}\label{wxlistboxclear}
139
140\func{void}{Clear}{\void}
141
142Clears all strings from the list box.
143
144\membersection{wxListBox::Create}\label{wxlistboxcreate}
145
eaaa6a06 146\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 147\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
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"}}
a660d684
KB
150
151Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxconstr}\rtfsp
152for further details.
153
154\membersection{wxListBox::Delete}\label{wxlistboxdelete}
155
156\func{void}{Delete}{\param{int}{ n}}
157
158Deletes 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
168Deselects 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
176This applies to multiple selection listboxes only.
177
178\membersection{wxListBox::FindString}\label{wxlistboxfindstring}
179
180\func{int}{FindString}{\param{const wxString\& }{string}}
181
182Finds an item matching the given string.
183
184\wxheading{Parameters}
185
186\docparam{string}{String to find.}
187
188\wxheading{Return value}
189
190The zero-based position of the item, or -1 if the string was not found.
191
192\membersection{wxListBox::GetClientData}\label{wxlistboxgetclientdata}
193
9c884972 194\constfunc{void*}{GetClientData}{\param{int}{ n}}
a660d684
KB
195
196Returns 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
204A pointer to the client data, or NULL if not present.
205
28ca7610
VZ
206\membersection{wxListBox::GetCount}\label{wxlistboxgetcount}
207
208\constfunc{int}{GetCount}{\void}
209
210Returns the number of items in the listbox.
211
a660d684
KB
212\membersection{wxListBox::GetSelection}\label{wxlistboxgetselection}
213
214\constfunc{int}{GetSelection}{\void}
215
216Gets the position of the selected item.
217
218\wxheading{Return value}
219
220The position of the current selection.
221
222\wxheading{Remarks}
223
224Applicable 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
605d715d 234\constfunc{int}{GetSelections}{\param{wxArrayInt\& }{selections}}
a660d684 235
fd9811b1 236Fill an array of ints with the positions of the currently selected items.
a660d684
KB
237
238\wxheading{Parameters}
239
fd9811b1 240\docparam{selections}{A reference to an wxArrayInt instance that is used to store the result of the query.}
a660d684
KB
241
242\wxheading{Return value}
243
244The number of selections.
245
246\wxheading{Remarks}
247
248Use 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
f899db6d
RD
256\pythonnote{The wxPython version of this method takes no parameters
257and returns a tuple of the selected items.}
258
2edb0bde 259\perlnote{In wxPerl this method takes no parameters and return the
5873607e
VZ
260selected items as a list.}
261
a660d684
KB
262\membersection{wxListBox::GetString}\label{wxlistboxgetstring}
263
eaaa6a06 264\constfunc{wxString}{GetString}{\param{int}{ n}}
a660d684
KB
265
266Returns the string at the given position.
267
268\wxheading{Parameters}
269
270\docparam{n}{The zero-based position.}
271
272\wxheading{Return value}
273
274The string, or an empty string if the position was invalid.
275
276\membersection{wxListBox::GetStringSelection}\label{wxlistboxgetstringselection}
277
278\constfunc{wxString}{GetStringSelection}{\void}
279
280Gets the selected string - for single selection list boxes only. This
281must be copied by the calling program if long term use is to be made of
282it.
283
284\wxheading{See also}
285
286\helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp
287\helpref{wxListBox::GetSelections}{wxlistboxgetselections},\rtfsp
288\helpref{wxListBox::SetSelection}{wxlistboxsetselection}
289
81108288
VZ
290\membersection{wxListBox::InsertItems}\label{wxlistboxinsertitems}
291
2b5f62a0 292\func{void}{InsertItems}{\param{int}{ nItems}, \param{const wxString}{ *items}, \param{int}{ pos}}
81108288
VZ
293
294Insert 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
303will be inserted in the beginning of the listbox}
304
76e1c2de
RD
305\pythonnote{The first two parameters are collapsed into a single
306parameter for wxPython, which is a list of strings.}
307
5873607e
VZ
308\perlnote{In wxPerl there is just an array reference in place of {\tt nItems}
309and {\tt items}.}
310
a660d684
KB
311\membersection{wxListBox::Number}\label{wxlistboxnumber}
312
313\constfunc{int}{Number}{\void}
314
28ca7610
VZ
315{\bf Obsolescence note:} This method is obsolete and was replaced with
316\helpref{GetCount}{wxlistboxgetcount}, please use the new method in the new
317code. This method is only available if wxWindows was compiled with
318{\tt WXWIN\_COMPATIBILITY\_2\_2} defined and will disappear completely in
319future versions.
320
a660d684
KB
321Returns the number of items in the listbox.
322
323\membersection{wxListBox::Selected}\label{wxlistboxselected}
324
eaaa6a06 325\constfunc{bool}{Selected}{\param{int}{ n}}
a660d684
KB
326
327Determines whether an item is selected.
328
329\wxheading{Parameters}
330
331\docparam{n}{The zero-based item index.}
332
333\wxheading{Return value}
334
335TRUE if the given item is selected, FALSE otherwise.
336
337\membersection{wxListBox::Set}\label{wxlistboxset}
338
2b5f62a0 339\func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
a660d684 340
2b5f62a0
VZ
341\func{void}{Set}{\param{const wxArrayString\&}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
342
343Clears the list box and adds the given strings to it.
a660d684
KB
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
2b5f62a0
VZ
351\docparam{clientData}{Options array of client data pointers}
352
a660d684
KB
353\wxheading{Remarks}
354
2b5f62a0
VZ
355You may free the array from the calling program after this function has been
356called.
a660d684
KB
357
358\membersection{wxListBox::SetClientData}\label{wxlistboxsetclientdata}
359
9c884972 360\func{void}{SetClientData}{\param{int}{ n}, \param{void* }{data}}
a660d684
KB
361
362Associates 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
953704c1 376Set the specified item to be the first visible item. Windows only.
a660d684
KB
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
eaaa6a06 386\func{void}{SetSelection}{\param{int}{ n}, \param{const bool }{select = TRUE}}
a660d684 387
953704c1
RR
388Selects or deselects the given item. This does not cause a
389wxEVT\_COMMAND\_LISTBOX\_SELECT event to get emitted.
a660d684
KB
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
eaaa6a06 399\func{void}{SetString}{\param{int}{ n}, \param{const wxString\& }{ string}}
a660d684
KB
400
401Sets 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
953704c1
RR
413Sets the current selection. This does not cause a
414wxEVT\_COMMAND\_LISTBOX\_SELECT event to get emitted.
a660d684
KB
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