1 \section{\class{wxListBox
}}\label{wxlistbox
}
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
10 List box elements are numbered from zero. Their number is limited in
11 some platforms (e.g. ca.
2000 on GTK).
13 A listbox callback gets an event wxEVT
\_COMMAND\_LISTBOX\_SELECT for single clicks, and
14 wxEVT
\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
16 \wxheading{Derived from
}
18 \helpref{wxControl
}{wxcontrol
}\\
19 \helpref{wxWindow
}{wxwindow
}\\
20 \helpref{wxEvtHandler
}{wxevthandler
}\\
21 \helpref{wxObject
}{wxobject
}
23 \wxheading{Include files
}
27 \wxheading{Window styles
}
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
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.
}
39 \twocolitem{\windowstyle{wxLB
\_SORT}}{The listbox contents are sorted in alphabetical order.
}
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).
46 See also
\helpref{window styles overview
}{windowstyles
}.
48 \wxheading{Event handling
}
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.
}
54 \twocolitem{{\bf EVT
\_LISTBOX\_DCLICK(id, func)
}}{Process a wxEVT
\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
55 when the listbox is double-clicked.
}
60 \helpref{wxChoice
}{wxchoice
},
\helpref{wxComboBox
}{wxcombobox
},
\helpref{wxListCtrl
}{wxlistctrl
},
61 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
63 \latexignore{\rtfignore{\wxheading{Members
}}}
65 \membersection{wxListBox::wxListBox
}\label{wxlistboxconstr
}
67 \func{}{wxListBox
}{\void}
71 \func{}{wxListBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
72 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
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"
}}
76 Constructor, creating and showing a list box.
78 \wxheading{Parameters
}
80 \docparam{parent
}{Parent window. Must not be NULL.
}
82 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
84 \docparam{pos
}{Window position.
}
86 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
89 \docparam{n
}{Number of strings with which to initialise the control.
}
91 \docparam{choices
}{An array of strings with which to initialise the control.
}
93 \docparam{style
}{Window style. See
\helpref{wxListBox
}{wxlistbox
}.
}
95 \docparam{validator
}{Window validator.
}
97 \docparam{name
}{Window name.
}
101 \helpref{wxListBox::Create
}{wxlistboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
103 \pythonnote{The wxListBox constructor in wxPython reduces the
{\tt n
}
104 and
{\tt choices
} arguments are to a single argument, which is
107 \perlnote{In wxPerl there is just an array reference in place of
{\tt n
}
110 \membersection{wxListBox::
\destruct{wxListBox
}}
112 \func{void
}{\destruct{wxListBox
}}{\void}
114 Destructor, destroying the list box.
116 \membersection{wxListBox::Append
}\label{wxlistboxappend
}
118 \func{int
}{Append
}{\param{const wxString\&
}{ item
}}
120 Adds the item to the end of the list box.
122 \func{int
}{Append
}{\param{const wxString\&
}{ item
},
\param{void*
}{clientData
}}
124 Adds the item to the end of the list box, associating the given data
127 \wxheading{Parameters
}
129 \docparam{item
}{String to add.
}
131 \docparam{clientData
}{Client data to associate with the item.
}
133 \wxheading{Return value
}
135 The index of the newly added item, may be different from the last one if the
136 control has
{\tt wxLB
\_SORT} style.
138 \membersection{wxListBox::Clear
}\label{wxlistboxclear
}
140 \func{void
}{Clear
}{\void}
142 Clears all strings from the list box.
144 \membersection{wxListBox::Create
}\label{wxlistboxcreate
}
146 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
147 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
148 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
149 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
151 Creates the listbox for two-step construction. See
\helpref{wxListBox::wxListBox
}{wxlistboxconstr
}\rtfsp
154 \membersection{wxListBox::Delete
}\label{wxlistboxdelete
}
156 \func{void
}{Delete
}{\param{int
}{ n
}}
158 Deletes an item from the listbox.
160 \wxheading{Parameters
}
162 \docparam{n
}{The zero-based item index.
}
164 \membersection{wxListBox::Deselect
}\label{wxlistboxdeselect
}
166 \func{void
}{Deselect
}{\param{int
}{ n
}}
168 Deselects an item in the list box.
170 \wxheading{Parameters
}
172 \docparam{n
}{The zero-based item to deselect.
}
176 This applies to multiple selection listboxes only.
178 \membersection{wxListBox::FindString
}\label{wxlistboxfindstring
}
180 \func{int
}{FindString
}{\param{const wxString\&
}{string
}}
182 Finds an item matching the given string.
184 \wxheading{Parameters
}
186 \docparam{string
}{String to find.
}
188 \wxheading{Return value
}
190 The zero-based position of the item, or -
1 if the string was not found.
192 \membersection{wxListBox::GetClientData
}\label{wxlistboxgetclientdata
}
194 \constfunc{void*
}{GetClientData
}{\param{int
}{ n
}}
196 Returns a pointer to the client data associated with the given item (if any).
198 \wxheading{Parameters
}
200 \docparam{n
}{The zero-based position of the item.
}
202 \wxheading{Return value
}
204 A pointer to the client data, or NULL if not present.
206 \membersection{wxListBox::GetCount
}\label{wxlistboxgetcount
}
208 \constfunc{int
}{GetCount
}{\void}
210 Returns the number of items in the listbox.
212 \membersection{wxListBox::GetSelection
}\label{wxlistboxgetselection
}
214 \constfunc{int
}{GetSelection
}{\void}
216 Gets the position of the selected item.
218 \wxheading{Return value
}
220 The position of the current selection.
224 Applicable to single selection list boxes only.
228 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
},
\rtfsp
229 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
230 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
}
232 \membersection{wxListBox::GetSelections
}\label{wxlistboxgetselections
}
234 \constfunc{int
}{GetSelections
}{\param{wxArrayInt\&
}{selections
}}
236 Fill an array of ints with the positions of the currently selected items.
238 \wxheading{Parameters
}
240 \docparam{selections
}{A reference to an wxArrayInt instance that is used to store the result of the query.
}
242 \wxheading{Return value
}
244 The number of selections.
248 Use this with a multiple selection listbox.
252 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
253 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
254 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
256 \pythonnote{The wxPython version of this method takes no parameters
257 and returns a tuple of the selected items.
}
259 \perlnote{In wxPerl this method takes no parameters and return the
260 selected items as a list.
}
262 \membersection{wxListBox::GetString
}\label{wxlistboxgetstring
}
264 \constfunc{wxString
}{GetString
}{\param{int
}{ n
}}
266 Returns the string at the given position.
268 \wxheading{Parameters
}
270 \docparam{n
}{The zero-based position.
}
272 \wxheading{Return value
}
274 The string, or an empty string if the position was invalid.
276 \membersection{wxListBox::GetStringSelection
}\label{wxlistboxgetstringselection
}
278 \constfunc{wxString
}{GetStringSelection
}{\void}
280 Gets the selected string - for single selection list boxes only. This
281 must be copied by the calling program if long term use is to be made of
286 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
287 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
},
\rtfsp
288 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
290 \membersection{wxListBox::InsertItems
}\label{wxlistboxinsertitems
}
292 \func{void
}{InsertItems
}{\param{int
}{ nItems
},
\param{const wxString
}{ *items
},
\param{int
}{ pos
}}
294 Insert the given number of strings before the specified position.
296 \wxheading{Parameters
}
298 \docparam{nItems
}{Number of items in the array
{\it items
}}
300 \docparam{items
}{Labels of items to be inserted
}
302 \docparam{pos
}{Position before which to insert the items: for example, if
{\it pos
} is
0 the items
303 will be inserted in the beginning of the listbox
}
305 \pythonnote{The first two parameters are collapsed into a single
306 parameter for wxPython, which is a list of strings.
}
308 \perlnote{In wxPerl there is just an array reference in place of
{\tt nItems
}
311 \membersection{wxListBox::Number
}\label{wxlistboxnumber
}
313 \constfunc{int
}{Number
}{\void}
315 {\bf Obsolescence note:
} This method is obsolete and was replaced with
316 \helpref{GetCount
}{wxlistboxgetcount
}, please use the new method in the new
317 code. This method is only available if wxWindows was compiled with
318 {\tt WXWIN
\_COMPATIBILITY\_2\_2} defined and will disappear completely in
321 Returns the number of items in the listbox.
323 \membersection{wxListBox::Selected
}\label{wxlistboxselected
}
325 \constfunc{bool
}{Selected
}{\param{int
}{ n
}}
327 Determines whether an item is selected.
329 \wxheading{Parameters
}
331 \docparam{n
}{The zero-based item index.
}
333 \wxheading{Return value
}
335 TRUE if the given item is selected, FALSE otherwise.
337 \membersection{wxListBox::Set
}\label{wxlistboxset
}
339 \func{void
}{Set
}{\param{int
}{ n
},
\param{const wxString*
}{ choices
},
\param{void
}{ **clientData =
{\tt NULL
}}}
341 \func{void
}{Set
}{\param{const wxArrayString\&
}{ choices
},
\param{void
}{ **clientData =
{\tt NULL
}}}
343 Clears the list box and adds the given strings to it.
345 \wxheading{Parameters
}
347 \docparam{n
}{The number of strings to set.
}
349 \docparam{choices
}{An array of strings to set.
}
351 \docparam{clientData
}{Options array of client data pointers
}
355 You may free the array from the calling program after this function has been
358 \membersection{wxListBox::SetClientData
}\label{wxlistboxsetclientdata
}
360 \func{void
}{SetClientData
}{\param{int
}{ n
},
\param{void*
}{data
}}
362 Associates the given client data pointer with the given item.
364 \wxheading{Parameters
}
366 \docparam{n
}{The zero-based item index.
}
368 \docparam{data
}{The client data to associate with the item.
}
370 \membersection{wxListBox::SetFirstItem
}\label{wxlistboxsetfirstitem
}
372 \func{void
}{SetFirstItem
}{\param{int
}{ n
}}
374 \func{void
}{SetFirstItem
}{\param{const wxString\&
}{string
}}
376 Set the specified item to be the first visible item. Windows only.
378 \wxheading{Parameters
}
380 \docparam{n
}{The zero-based item index.
}
382 \docparam{string
}{The string that should be visible.
}
384 \membersection{wxListBox::SetSelection
}\label{wxlistboxsetselection
}
386 \func{void
}{SetSelection
}{\param{int
}{ n
},
\param{const bool
}{select = TRUE
}}
388 Selects or deselects the given item. This does not cause a
389 wxEVT
\_COMMAND\_LISTBOX\_SELECT event to get emitted.
391 \wxheading{Parameters
}
393 \docparam{n
}{The zero-based item index.
}
395 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}
397 \membersection{wxListBox::SetString
}\label{wxlistboxsetstring
}
399 \func{void
}{SetString
}{\param{int
}{ n
},
\param{const wxString\&
}{ string
}}
401 Sets the string value of an item.
403 \wxheading{Parameters
}
405 \docparam{n
}{The zero-based item index.
}
407 \docparam{string
}{The string to set.
}
409 \membersection{wxListBox::SetStringSelection
}\label{wxlistboxsetstringselection
}
411 \func{void
}{SetStringSelection
}{\param{const wxString\&
}{ string
},
\param{const bool
}{ select = TRUE
}}
413 Sets the current selection. This does not cause a
414 wxEVT
\_COMMAND\_LISTBOX\_SELECT event to get emitted.
416 \wxheading{Parameters
}
418 \docparam{string
}{The item to select.
}
420 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}