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