]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/listbox.tex
wxToolBar API changes; now frames manage their toolbar & statusbar properly;
[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
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
28items on and off.}
29\twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can
30select 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
37See 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
49Default constructor.
50
eaaa6a06 51\func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 52\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
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"}}
a660d684
KB
55
56Constructor, 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
67appropriately.}
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
87Destructor, destroying the list box.
88
89\membersection{wxListBox::Append}\label{wxlistboxappend}
90
91\func{void}{Append}{\param{const wxString\& }{ item}}
92
93Adds the item to the end of the list box.
94
95\func{void}{Append}{\param{const wxString\& }{ item}, \param{char* }{clientData}}
96
97Adds the item to the end of the list box, associating the given data
98with 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
110Clears all strings from the list box.
111
112\membersection{wxListBox::Create}\label{wxlistboxcreate}
113
eaaa6a06 114\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 115\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
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"}}
a660d684
KB
118
119Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxconstr}\rtfsp
120for further details.
121
122\membersection{wxListBox::Delete}\label{wxlistboxdelete}
123
124\func{void}{Delete}{\param{int}{ n}}
125
126Deletes 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
136Deselects 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
144This applies to multiple selection listboxes only.
145
146\membersection{wxListBox::FindString}\label{wxlistboxfindstring}
147
148\func{int}{FindString}{\param{const wxString\& }{string}}
149
150Finds an item matching the given string.
151
152\wxheading{Parameters}
153
154\docparam{string}{String to find.}
155
156\wxheading{Return value}
157
158The zero-based position of the item, or -1 if the string was not found.
159
160\membersection{wxListBox::GetClientData}\label{wxlistboxgetclientdata}
161
eaaa6a06 162\constfunc{char*}{GetClientData}{\param{int}{ n}}
a660d684
KB
163
164Returns 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
172A pointer to the client data, or NULL if not present.
173
174\membersection{wxListBox::GetSelection}\label{wxlistboxgetselection}
175
176\constfunc{int}{GetSelection}{\void}
177
178Gets the position of the selected item.
179
180\wxheading{Return value}
181
182The position of the current selection.
183
184\wxheading{Remarks}
185
186Applicable 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
198Gets 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
203selects are present. Do not deallocate the returned array - it will be deallocated by the listbox.}
204
205\wxheading{Return value}
206
207The number of selections.
208
209\wxheading{Remarks}
210
211Use 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
eaaa6a06 221\constfunc{wxString}{GetString}{\param{int}{ n}}
a660d684
KB
222
223Returns the string at the given position.
224
225\wxheading{Parameters}
226
227\docparam{n}{The zero-based position.}
228
229\wxheading{Return value}
230
231The string, or an empty string if the position was invalid.
232
233\membersection{wxListBox::GetStringSelection}\label{wxlistboxgetstringselection}
234
235\constfunc{wxString}{GetStringSelection}{\void}
236
237Gets the selected string - for single selection list boxes only. This
238must be copied by the calling program if long term use is to be made of
239it.
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
251Returns the number of items in the listbox.
252
253\membersection{wxListBox::Selected}\label{wxlistboxselected}
254
eaaa6a06 255\constfunc{bool}{Selected}{\param{int}{ n}}
a660d684
KB
256
257Determines whether an item is selected.
258
259\wxheading{Parameters}
260
261\docparam{n}{The zero-based item index.}
262
263\wxheading{Return value}
264
265TRUE if the given item is selected, FALSE otherwise.
266
267\membersection{wxListBox::Set}\label{wxlistboxset}
268
eaaa6a06 269\func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}}
a660d684
KB
270
271Clears 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
281Deallocate the array from the calling program
282after this function has been called.
283
284\membersection{wxListBox::SetClientData}\label{wxlistboxsetclientdata}
285
eaaa6a06 286\func{void}{SetClientData}{\param{int}{ n}, \param{char* }{data}}
a660d684
KB
287
288Associates 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
302Set 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
eaaa6a06 312\func{void}{SetSelection}{\param{int}{ n}, \param{const bool }{select = TRUE}}
a660d684
KB
313
314Selects 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
eaaa6a06 324\func{void}{SetString}{\param{int}{ n}, \param{const wxString\& }{ string}}
a660d684
KB
325
326Sets 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
338Sets 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