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