]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/listbox.tex
wxExecute() fixes and doc updates: the return value for sync exec case is now
[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
10List box elements are numbered from zero.
11
12A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECT for single clicks, and
debe6624 13wxEVT\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
a660d684
KB
14
15\wxheading{Derived from}
16
17\helpref{wxControl}{wxcontrol}\\
18\helpref{wxWindow}{wxwindow}\\
19\helpref{wxEvtHandler}{wxevthandler}\\
20\helpref{wxObject}{wxobject}
21
954b8ae6
JS
22\wxheading{Include files}
23
24<wx/listbox.h>
25
a660d684
KB
26\wxheading{Window styles}
27
28\twocolwidtha{5cm}%
29\begin{twocollist}\itemsep=0pt
30\twocolitem{\windowstyle{wxLB\_SINGLE}}{Single-selection list.}
31\twocolitem{\windowstyle{wxLB\_MULTIPLE}}{Multiple-selection list: the user can toggle multiple
32items on and off.}
33\twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can
34select multiple items using the SHIFT key and the mouse or special key combinations.}
35\twocolitem{\windowstyle{wxLB\_HSCROLL}}{Create horizontal scrollbar if contents are too wide (Windows only).}
36\twocolitem{\windowstyle{wxLB\_ALWAYS\_SB}}{Always show a vertical scrollbar.}
37\twocolitem{\windowstyle{wxLB\_NEEDED\_SB}}{Only create a vertical scrollbar if needed.}
38\twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.}
39\end{twocollist}
40
41See also \helpref{window styles overview}{windowstyles}.
42
5de76427
JS
43\wxheading{Event handling}
44
45\twocolwidtha{7cm}
46\begin{twocollist}\itemsep=0pt
47\twocolitem{{\bf EVT\_LISTBOX(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_SELECTED event,
48when an item on the list is selected.}
def172b2 49\twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
5de76427
JS
50when the listbox is doubleclicked.}
51\end{twocollist}
52
a660d684
KB
53\wxheading{See also}
54
5de76427
JS
55\helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl},
56\rtfsp\helpref{wxCommandEvent}{wxcommandevent}
a660d684
KB
57
58\latexignore{\rtfignore{\wxheading{Members}}}
59
60\membersection{wxListBox::wxListBox}\label{wxlistboxconstr}
61
62\func{}{wxListBox}{\void}
63
64Default constructor.
65
eaaa6a06 66\func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 67\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
68\param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
69\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
a660d684
KB
70
71Constructor, creating and showing a list box.
72
73\wxheading{Parameters}
74
75\docparam{parent}{Parent window. Must not be NULL.}
76
77\docparam{id}{Window identifier. A value of -1 indicates a default value.}
78
79\docparam{pos}{Window position.}
80
81\docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
82appropriately.}
83
84\docparam{n}{Number of strings with which to initialise the control.}
85
86\docparam{choices}{An array of strings with which to initialise the control.}
87
88\docparam{style}{Window style. See \helpref{wxListBox}{wxlistbox}.}
89
90\docparam{validator}{Window validator.}
91
92\docparam{name}{Window name.}
93
94\wxheading{See also}
95
96\helpref{wxListBox::Create}{wxlistboxcreate}, \helpref{wxValidator}{wxvalidator}
97
98\membersection{wxListBox::\destruct{wxListBox}}
99
100\func{void}{\destruct{wxListBox}}{\void}
101
102Destructor, destroying the list box.
103
104\membersection{wxListBox::Append}\label{wxlistboxappend}
105
106\func{void}{Append}{\param{const wxString\& }{ item}}
107
108Adds the item to the end of the list box.
109
110\func{void}{Append}{\param{const wxString\& }{ item}, \param{char* }{clientData}}
111
112Adds the item to the end of the list box, associating the given data
113with the item.
114
115\wxheading{Parameters}
116
117\docparam{item}{String to add.}
118
119\docparam{clientData}{Client data to associate with the item.}
120
121\membersection{wxListBox::Clear}\label{wxlistboxclear}
122
123\func{void}{Clear}{\void}
124
125Clears all strings from the list box.
126
127\membersection{wxListBox::Create}\label{wxlistboxcreate}
128
eaaa6a06 129\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 130\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
131\param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
132\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
a660d684
KB
133
134Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxconstr}\rtfsp
135for further details.
136
137\membersection{wxListBox::Delete}\label{wxlistboxdelete}
138
139\func{void}{Delete}{\param{int}{ n}}
140
141Deletes an item from the listbox.
142
143\wxheading{Parameters}
144
145\docparam{n}{The zero-based item index.}
146
147\membersection{wxListBox::Deselect}\label{wxlistboxdeselect}
148
149\func{void}{Deselect}{\param{int}{ n}}
150
151Deselects an item in the list box.
152
153\wxheading{Parameters}
154
155\docparam{n}{The zero-based item to deselect.}
156
157\wxheading{Remarks}
158
159This applies to multiple selection listboxes only.
160
161\membersection{wxListBox::FindString}\label{wxlistboxfindstring}
162
163\func{int}{FindString}{\param{const wxString\& }{string}}
164
165Finds an item matching the given string.
166
167\wxheading{Parameters}
168
169\docparam{string}{String to find.}
170
171\wxheading{Return value}
172
173The zero-based position of the item, or -1 if the string was not found.
174
175\membersection{wxListBox::GetClientData}\label{wxlistboxgetclientdata}
176
eaaa6a06 177\constfunc{char*}{GetClientData}{\param{int}{ n}}
a660d684
KB
178
179Returns a pointer to the client data associated with the given item (if any).
180
181\wxheading{Parameters}
182
183\docparam{n}{The zero-based position of the item.}
184
185\wxheading{Return value}
186
187A pointer to the client data, or NULL if not present.
188
189\membersection{wxListBox::GetSelection}\label{wxlistboxgetselection}
190
191\constfunc{int}{GetSelection}{\void}
192
193Gets the position of the selected item.
194
195\wxheading{Return value}
196
197The position of the current selection.
198
199\wxheading{Remarks}
200
201Applicable to single selection list boxes only.
202
203\wxheading{See also}
204
205\helpref{wxListBox::SetSelection}{wxlistboxsetselection},\rtfsp
206\helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp
207\helpref{wxListBox::GetSelections}{wxlistboxgetselections}
208
209\membersection{wxListBox::GetSelections}\label{wxlistboxgetselections}
210
211\constfunc{int}{GetSelections}{\param{int **}{selections}}
212
213Gets an array containing the positions of the selected strings.
214
215\wxheading{Parameters}
216
217\docparam{selections}{A pointer to an integer array, which will be allocated by the function if
218selects are present. Do not deallocate the returned array - it will be deallocated by the listbox.}
219
220\wxheading{Return value}
221
222The number of selections.
223
224\wxheading{Remarks}
225
226Use this with a multiple selection listbox.
227
228\wxheading{See also}
229
230\helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp
231\helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp
232\helpref{wxListBox::SetSelection}{wxlistboxsetselection}
233
234\membersection{wxListBox::GetString}\label{wxlistboxgetstring}
235
eaaa6a06 236\constfunc{wxString}{GetString}{\param{int}{ n}}
a660d684
KB
237
238Returns the string at the given position.
239
240\wxheading{Parameters}
241
242\docparam{n}{The zero-based position.}
243
244\wxheading{Return value}
245
246The string, or an empty string if the position was invalid.
247
248\membersection{wxListBox::GetStringSelection}\label{wxlistboxgetstringselection}
249
250\constfunc{wxString}{GetStringSelection}{\void}
251
252Gets the selected string - for single selection list boxes only. This
253must be copied by the calling program if long term use is to be made of
254it.
255
256\wxheading{See also}
257
258\helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp
259\helpref{wxListBox::GetSelections}{wxlistboxgetselections},\rtfsp
260\helpref{wxListBox::SetSelection}{wxlistboxsetselection}
261
262\membersection{wxListBox::Number}\label{wxlistboxnumber}
263
264\constfunc{int}{Number}{\void}
265
266Returns the number of items in the listbox.
267
268\membersection{wxListBox::Selected}\label{wxlistboxselected}
269
eaaa6a06 270\constfunc{bool}{Selected}{\param{int}{ n}}
a660d684
KB
271
272Determines whether an item is selected.
273
274\wxheading{Parameters}
275
276\docparam{n}{The zero-based item index.}
277
278\wxheading{Return value}
279
280TRUE if the given item is selected, FALSE otherwise.
281
282\membersection{wxListBox::Set}\label{wxlistboxset}
283
eaaa6a06 284\func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}}
a660d684
KB
285
286Clears the list box and adds the given strings.
287
288\wxheading{Parameters}
289
290\docparam{n}{The number of strings to set.}
291
292\docparam{choices}{An array of strings to set.}
293
294\wxheading{Remarks}
295
296Deallocate the array from the calling program
297after this function has been called.
298
299\membersection{wxListBox::SetClientData}\label{wxlistboxsetclientdata}
300
eaaa6a06 301\func{void}{SetClientData}{\param{int}{ n}, \param{char* }{data}}
a660d684
KB
302
303Associates the given client data pointer with the given item.
304
305\wxheading{Parameters}
306
307\docparam{n}{The zero-based item index.}
308
309\docparam{data}{The client data to associate with the item.}
310
311\membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem}
312
313\func{void}{SetFirstItem}{\param{int}{ n}}
314
315\func{void}{SetFirstItem}{\param{const wxString\& }{string}}
316
317Set the specified item to be the first visible item.
318
319\wxheading{Parameters}
320
321\docparam{n}{The zero-based item index.}
322
323\docparam{string}{The string that should be visible.}
324
325\membersection{wxListBox::SetSelection}\label{wxlistboxsetselection}
326
eaaa6a06 327\func{void}{SetSelection}{\param{int}{ n}, \param{const bool }{select = TRUE}}
a660d684
KB
328
329Selects or deselects the given item.
330
331\wxheading{Parameters}
332
333\docparam{n}{The zero-based item index.}
334
335\docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.}
336
337\membersection{wxListBox::SetString}\label{wxlistboxsetstring}
338
eaaa6a06 339\func{void}{SetString}{\param{int}{ n}, \param{const wxString\& }{ string}}
a660d684
KB
340
341Sets the string value of an item.
342
343\wxheading{Parameters}
344
345\docparam{n}{The zero-based item index.}
346
347\docparam{string}{The string to set.}
348
349\membersection{wxListBox::SetStringSelection}\label{wxlistboxsetstringselection}
350
351\func{void}{SetStringSelection}{\param{const wxString\& }{ string}, \param{const bool}{ select = TRUE}}
352
353Sets the current selection.
354
355\wxheading{Parameters}
356
357\docparam{string}{The item to select.}
358
359\docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.}
360