]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
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 | ||
27d029c7 RR |
10 | List box elements are numbered from zero. Their number is limited in |
11 | some platforms (e.g. ca. 2000 on GTK). | |
a660d684 KB |
12 | |
13 | A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECT for single clicks, and | |
debe6624 | 14 | wxEVT\_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 | |
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.} | |
3377b962 | 39 | \twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.} |
a660d684 KB |
40 | \end{twocollist} |
41 | ||
54081dc5 VZ |
42 | Note that {\tt wxLB\_SINGLE}, {\tt wxLB\_MULTIPLE} and {\tt wxLB\_EXTENDED} |
43 | styles are mutually exclusive and you can specify at most one of them (single | |
44 | selection is the default). | |
45 | ||
a660d684 KB |
46 | See 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, | |
53 | when an item on the list is selected.} | |
def172b2 | 54 | \twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event, |
2edb0bde | 55 | when 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 | ||
69 | Default 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 | |
76 | Constructor, 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 | |
87 | appropriately.} | |
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} |
104 | and {\tt choices} arguments are to a single argument, which is | |
06d20283 RD |
105 | a list of strings.} |
106 | ||
5873607e VZ |
107 | \perlnote{In wxPerl there is just an array reference in place of {\tt n} |
108 | and {\tt choices}.} | |
06d20283 | 109 | |
a660d684 KB |
110 | \membersection{wxListBox::\destruct{wxListBox}} |
111 | ||
112 | \func{void}{\destruct{wxListBox}}{\void} | |
113 | ||
114 | Destructor, destroying the list box. | |
115 | ||
116 | \membersection{wxListBox::Append}\label{wxlistboxappend} | |
117 | ||
118 | \func{void}{Append}{\param{const wxString\& }{ item}} | |
119 | ||
120 | Adds the item to the end of the list box. | |
121 | ||
9c884972 | 122 | \func{void}{Append}{\param{const wxString\& }{ item}, \param{void* }{clientData}} |
a660d684 KB |
123 | |
124 | Adds the item to the end of the list box, associating the given data | |
125 | with 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 | ||
133 | \membersection{wxListBox::Clear}\label{wxlistboxclear} | |
134 | ||
135 | \func{void}{Clear}{\void} | |
136 | ||
137 | Clears all strings from the list box. | |
138 | ||
139 | \membersection{wxListBox::Create}\label{wxlistboxcreate} | |
140 | ||
eaaa6a06 | 141 | \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp |
a660d684 | 142 | \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp |
eaaa6a06 JS |
143 | \param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp |
144 | \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}} | |
a660d684 KB |
145 | |
146 | Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxconstr}\rtfsp | |
147 | for further details. | |
148 | ||
149 | \membersection{wxListBox::Delete}\label{wxlistboxdelete} | |
150 | ||
151 | \func{void}{Delete}{\param{int}{ n}} | |
152 | ||
153 | Deletes an item from the listbox. | |
154 | ||
155 | \wxheading{Parameters} | |
156 | ||
157 | \docparam{n}{The zero-based item index.} | |
158 | ||
159 | \membersection{wxListBox::Deselect}\label{wxlistboxdeselect} | |
160 | ||
161 | \func{void}{Deselect}{\param{int}{ n}} | |
162 | ||
163 | Deselects an item in the list box. | |
164 | ||
165 | \wxheading{Parameters} | |
166 | ||
167 | \docparam{n}{The zero-based item to deselect.} | |
168 | ||
169 | \wxheading{Remarks} | |
170 | ||
171 | This applies to multiple selection listboxes only. | |
172 | ||
173 | \membersection{wxListBox::FindString}\label{wxlistboxfindstring} | |
174 | ||
175 | \func{int}{FindString}{\param{const wxString\& }{string}} | |
176 | ||
177 | Finds an item matching the given string. | |
178 | ||
179 | \wxheading{Parameters} | |
180 | ||
181 | \docparam{string}{String to find.} | |
182 | ||
183 | \wxheading{Return value} | |
184 | ||
185 | The zero-based position of the item, or -1 if the string was not found. | |
186 | ||
187 | \membersection{wxListBox::GetClientData}\label{wxlistboxgetclientdata} | |
188 | ||
9c884972 | 189 | \constfunc{void*}{GetClientData}{\param{int}{ n}} |
a660d684 KB |
190 | |
191 | Returns a pointer to the client data associated with the given item (if any). | |
192 | ||
193 | \wxheading{Parameters} | |
194 | ||
195 | \docparam{n}{The zero-based position of the item.} | |
196 | ||
197 | \wxheading{Return value} | |
198 | ||
199 | A pointer to the client data, or NULL if not present. | |
200 | ||
28ca7610 VZ |
201 | \membersection{wxListBox::GetCount}\label{wxlistboxgetcount} |
202 | ||
203 | \constfunc{int}{GetCount}{\void} | |
204 | ||
205 | Returns the number of items in the listbox. | |
206 | ||
a660d684 KB |
207 | \membersection{wxListBox::GetSelection}\label{wxlistboxgetselection} |
208 | ||
209 | \constfunc{int}{GetSelection}{\void} | |
210 | ||
211 | Gets the position of the selected item. | |
212 | ||
213 | \wxheading{Return value} | |
214 | ||
215 | The position of the current selection. | |
216 | ||
217 | \wxheading{Remarks} | |
218 | ||
219 | Applicable to single selection list boxes only. | |
220 | ||
221 | \wxheading{See also} | |
222 | ||
223 | \helpref{wxListBox::SetSelection}{wxlistboxsetselection},\rtfsp | |
224 | \helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp | |
225 | \helpref{wxListBox::GetSelections}{wxlistboxgetselections} | |
226 | ||
227 | \membersection{wxListBox::GetSelections}\label{wxlistboxgetselections} | |
228 | ||
605d715d | 229 | \constfunc{int}{GetSelections}{\param{wxArrayInt\& }{selections}} |
a660d684 | 230 | |
fd9811b1 | 231 | Fill an array of ints with the positions of the currently selected items. |
a660d684 KB |
232 | |
233 | \wxheading{Parameters} | |
234 | ||
fd9811b1 | 235 | \docparam{selections}{A reference to an wxArrayInt instance that is used to store the result of the query.} |
a660d684 KB |
236 | |
237 | \wxheading{Return value} | |
238 | ||
239 | The number of selections. | |
240 | ||
241 | \wxheading{Remarks} | |
242 | ||
243 | Use this with a multiple selection listbox. | |
244 | ||
245 | \wxheading{See also} | |
246 | ||
247 | \helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp | |
248 | \helpref{wxListBox::GetStringSelection}{wxlistboxgetstringselection},\rtfsp | |
249 | \helpref{wxListBox::SetSelection}{wxlistboxsetselection} | |
250 | ||
f899db6d RD |
251 | \pythonnote{The wxPython version of this method takes no parameters |
252 | and returns a tuple of the selected items.} | |
253 | ||
2edb0bde | 254 | \perlnote{In wxPerl this method takes no parameters and return the |
5873607e VZ |
255 | selected items as a list.} |
256 | ||
a660d684 KB |
257 | \membersection{wxListBox::GetString}\label{wxlistboxgetstring} |
258 | ||
eaaa6a06 | 259 | \constfunc{wxString}{GetString}{\param{int}{ n}} |
a660d684 KB |
260 | |
261 | Returns the string at the given position. | |
262 | ||
263 | \wxheading{Parameters} | |
264 | ||
265 | \docparam{n}{The zero-based position.} | |
266 | ||
267 | \wxheading{Return value} | |
268 | ||
269 | The string, or an empty string if the position was invalid. | |
270 | ||
271 | \membersection{wxListBox::GetStringSelection}\label{wxlistboxgetstringselection} | |
272 | ||
273 | \constfunc{wxString}{GetStringSelection}{\void} | |
274 | ||
275 | Gets the selected string - for single selection list boxes only. This | |
276 | must be copied by the calling program if long term use is to be made of | |
277 | it. | |
278 | ||
279 | \wxheading{See also} | |
280 | ||
281 | \helpref{wxListBox::GetSelection}{wxlistboxgetselection},\rtfsp | |
282 | \helpref{wxListBox::GetSelections}{wxlistboxgetselections},\rtfsp | |
283 | \helpref{wxListBox::SetSelection}{wxlistboxsetselection} | |
284 | ||
81108288 VZ |
285 | \membersection{wxListBox::InsertItems}\label{wxlistboxinsertitems} |
286 | ||
287 | \func{void}{InsertItems}{\param{int}{ nItems}, \param{const wxString}{ items}, \param{int}{ pos}} | |
288 | ||
289 | Insert the given number of strings before the specified position. | |
290 | ||
291 | \wxheading{Parameters} | |
292 | ||
293 | \docparam{nItems}{Number of items in the array {\it items}} | |
294 | ||
295 | \docparam{items}{Labels of items to be inserted} | |
296 | ||
297 | \docparam{pos}{Position before which to insert the items: for example, if {\it pos} is 0 the items | |
298 | will be inserted in the beginning of the listbox} | |
299 | ||
76e1c2de RD |
300 | \pythonnote{The first two parameters are collapsed into a single |
301 | parameter for wxPython, which is a list of strings.} | |
302 | ||
5873607e VZ |
303 | \perlnote{In wxPerl there is just an array reference in place of {\tt nItems} |
304 | and {\tt items}.} | |
305 | ||
a660d684 KB |
306 | \membersection{wxListBox::Number}\label{wxlistboxnumber} |
307 | ||
308 | \constfunc{int}{Number}{\void} | |
309 | ||
28ca7610 VZ |
310 | {\bf Obsolescence note:} This method is obsolete and was replaced with |
311 | \helpref{GetCount}{wxlistboxgetcount}, please use the new method in the new | |
312 | code. This method is only available if wxWindows was compiled with | |
313 | {\tt WXWIN\_COMPATIBILITY\_2\_2} defined and will disappear completely in | |
314 | future versions. | |
315 | ||
a660d684 KB |
316 | Returns the number of items in the listbox. |
317 | ||
318 | \membersection{wxListBox::Selected}\label{wxlistboxselected} | |
319 | ||
eaaa6a06 | 320 | \constfunc{bool}{Selected}{\param{int}{ n}} |
a660d684 KB |
321 | |
322 | Determines whether an item is selected. | |
323 | ||
324 | \wxheading{Parameters} | |
325 | ||
326 | \docparam{n}{The zero-based item index.} | |
327 | ||
328 | \wxheading{Return value} | |
329 | ||
330 | TRUE if the given item is selected, FALSE otherwise. | |
331 | ||
332 | \membersection{wxListBox::Set}\label{wxlistboxset} | |
333 | ||
eaaa6a06 | 334 | \func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}} |
a660d684 | 335 | |
9c884972 | 336 | Clears the list box and adds the given strings. Not implemented for GTK. |
a660d684 KB |
337 | |
338 | \wxheading{Parameters} | |
339 | ||
340 | \docparam{n}{The number of strings to set.} | |
341 | ||
342 | \docparam{choices}{An array of strings to set.} | |
343 | ||
344 | \wxheading{Remarks} | |
345 | ||
346 | Deallocate the array from the calling program | |
347 | after this function has been called. | |
348 | ||
349 | \membersection{wxListBox::SetClientData}\label{wxlistboxsetclientdata} | |
350 | ||
9c884972 | 351 | \func{void}{SetClientData}{\param{int}{ n}, \param{void* }{data}} |
a660d684 KB |
352 | |
353 | Associates the given client data pointer with the given item. | |
354 | ||
355 | \wxheading{Parameters} | |
356 | ||
357 | \docparam{n}{The zero-based item index.} | |
358 | ||
359 | \docparam{data}{The client data to associate with the item.} | |
360 | ||
361 | \membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem} | |
362 | ||
363 | \func{void}{SetFirstItem}{\param{int}{ n}} | |
364 | ||
365 | \func{void}{SetFirstItem}{\param{const wxString\& }{string}} | |
366 | ||
953704c1 | 367 | Set the specified item to be the first visible item. Windows only. |
a660d684 KB |
368 | |
369 | \wxheading{Parameters} | |
370 | ||
371 | \docparam{n}{The zero-based item index.} | |
372 | ||
373 | \docparam{string}{The string that should be visible.} | |
374 | ||
375 | \membersection{wxListBox::SetSelection}\label{wxlistboxsetselection} | |
376 | ||
eaaa6a06 | 377 | \func{void}{SetSelection}{\param{int}{ n}, \param{const bool }{select = TRUE}} |
a660d684 | 378 | |
953704c1 RR |
379 | Selects or deselects the given item. This does not cause a |
380 | wxEVT\_COMMAND\_LISTBOX\_SELECT event to get emitted. | |
a660d684 KB |
381 | |
382 | \wxheading{Parameters} | |
383 | ||
384 | \docparam{n}{The zero-based item index.} | |
385 | ||
386 | \docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.} | |
387 | ||
388 | \membersection{wxListBox::SetString}\label{wxlistboxsetstring} | |
389 | ||
eaaa6a06 | 390 | \func{void}{SetString}{\param{int}{ n}, \param{const wxString\& }{ string}} |
a660d684 KB |
391 | |
392 | Sets the string value of an item. | |
393 | ||
394 | \wxheading{Parameters} | |
395 | ||
396 | \docparam{n}{The zero-based item index.} | |
397 | ||
398 | \docparam{string}{The string to set.} | |
399 | ||
400 | \membersection{wxListBox::SetStringSelection}\label{wxlistboxsetstringselection} | |
401 | ||
402 | \func{void}{SetStringSelection}{\param{const wxString\& }{ string}, \param{const bool}{ select = TRUE}} | |
403 | ||
953704c1 RR |
404 | Sets the current selection. This does not cause a |
405 | wxEVT\_COMMAND\_LISTBOX\_SELECT event to get emitted. | |
a660d684 KB |
406 | |
407 | \wxheading{Parameters} | |
408 | ||
409 | \docparam{string}{The item to select.} | |
410 | ||
411 | \docparam{select}{If TRUE, will select the item. If FALSE, will deselect it.} | |
412 |