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