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 See also
\helpref{window styles overview
}{windowstyles
}.
44 \wxheading{Event handling
}
47 \begin{twocollist
}\itemsep=
0pt
48 \twocolitem{{\bf EVT
\_LISTBOX(id, func)
}}{Process a wxEVT
\_COMMAND\_LISTBOX\_SELECTED event,
49 when an item on the list is selected.
}
50 \twocolitem{{\bf EVT
\_LISTBOX\_DCLICK(id, func)
}}{Process a wxEVT
\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
51 when the listbox is doubleclicked.
}
56 \helpref{wxChoice
}{wxchoice
},
\helpref{wxComboBox
}{wxcombobox
},
\helpref{wxListCtrl
}{wxlistctrl
},
57 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
59 \latexignore{\rtfignore{\wxheading{Members
}}}
61 \membersection{wxListBox::wxListBox
}\label{wxlistboxconstr
}
63 \func{}{wxListBox
}{\void}
67 \func{}{wxListBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
68 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
69 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
70 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
72 Constructor, creating and showing a list box.
74 \wxheading{Parameters
}
76 \docparam{parent
}{Parent window. Must not be NULL.
}
78 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
80 \docparam{pos
}{Window position.
}
82 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
85 \docparam{n
}{Number of strings with which to initialise the control.
}
87 \docparam{choices
}{An array of strings with which to initialise the control.
}
89 \docparam{style
}{Window style. See
\helpref{wxListBox
}{wxlistbox
}.
}
91 \docparam{validator
}{Window validator.
}
93 \docparam{name
}{Window name.
}
97 \helpref{wxListBox::Create
}{wxlistboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
99 \pythonnote{The wxListBox constructor in wxPython reduces the
{\tt n
}
100 and
{\tt choices
} arguments are to a single argument, which is
103 \perlnote{In wxPerl there is just an array reference in place of
{\tt n
}
106 \membersection{wxListBox::
\destruct{wxListBox
}}
108 \func{void
}{\destruct{wxListBox
}}{\void}
110 Destructor, destroying the list box.
112 \membersection{wxListBox::Append
}\label{wxlistboxappend
}
114 \func{void
}{Append
}{\param{const wxString\&
}{ item
}}
116 Adds the item to the end of the list box.
118 \func{void
}{Append
}{\param{const wxString\&
}{ item
},
\param{void*
}{clientData
}}
120 Adds the item to the end of the list box, associating the given data
123 \wxheading{Parameters
}
125 \docparam{item
}{String to add.
}
127 \docparam{clientData
}{Client data to associate with the item.
}
129 \membersection{wxListBox::Clear
}\label{wxlistboxclear
}
131 \func{void
}{Clear
}{\void}
133 Clears all strings from the list box.
135 \membersection{wxListBox::Create
}\label{wxlistboxcreate
}
137 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
138 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
139 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
140 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
142 Creates the listbox for two-step construction. See
\helpref{wxListBox::wxListBox
}{wxlistboxconstr
}\rtfsp
145 \membersection{wxListBox::Delete
}\label{wxlistboxdelete
}
147 \func{void
}{Delete
}{\param{int
}{ n
}}
149 Deletes an item from the listbox.
151 \wxheading{Parameters
}
153 \docparam{n
}{The zero-based item index.
}
155 \membersection{wxListBox::Deselect
}\label{wxlistboxdeselect
}
157 \func{void
}{Deselect
}{\param{int
}{ n
}}
159 Deselects an item in the list box.
161 \wxheading{Parameters
}
163 \docparam{n
}{The zero-based item to deselect.
}
167 This applies to multiple selection listboxes only.
169 \membersection{wxListBox::FindString
}\label{wxlistboxfindstring
}
171 \func{int
}{FindString
}{\param{const wxString\&
}{string
}}
173 Finds an item matching the given string.
175 \wxheading{Parameters
}
177 \docparam{string
}{String to find.
}
179 \wxheading{Return value
}
181 The zero-based position of the item, or -
1 if the string was not found.
183 \membersection{wxListBox::GetClientData
}\label{wxlistboxgetclientdata
}
185 \constfunc{void*
}{GetClientData
}{\param{int
}{ n
}}
187 Returns a pointer to the client data associated with the given item (if any).
189 \wxheading{Parameters
}
191 \docparam{n
}{The zero-based position of the item.
}
193 \wxheading{Return value
}
195 A pointer to the client data, or NULL if not present.
197 \membersection{wxListBox::GetSelection
}\label{wxlistboxgetselection
}
199 \constfunc{int
}{GetSelection
}{\void}
201 Gets the position of the selected item.
203 \wxheading{Return value
}
205 The position of the current selection.
209 Applicable to single selection list boxes only.
213 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
},
\rtfsp
214 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
215 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
}
217 \membersection{wxListBox::GetSelections
}\label{wxlistboxgetselections
}
219 \constfunc{int
}{GetSelections
}{\param{wxArrayInt\&
}{selections
}}
221 Fill an array of ints with the positions of the currently selected items.
223 \wxheading{Parameters
}
225 \docparam{selections
}{A reference to an wxArrayInt instance that is used to store the result of the query.
}
227 \wxheading{Return value
}
229 The number of selections.
233 Use this with a multiple selection listbox.
237 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
238 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
239 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
241 \pythonnote{The wxPython version of this method takes no parameters
242 and returns a tuple of the selected items.
}
244 \perlnote{In wxPerl this method takes no parameters and returna the
245 selected items as a list.
}
247 \membersection{wxListBox::GetString
}\label{wxlistboxgetstring
}
249 \constfunc{wxString
}{GetString
}{\param{int
}{ n
}}
251 Returns the string at the given position.
253 \wxheading{Parameters
}
255 \docparam{n
}{The zero-based position.
}
257 \wxheading{Return value
}
259 The string, or an empty string if the position was invalid.
261 \membersection{wxListBox::GetStringSelection
}\label{wxlistboxgetstringselection
}
263 \constfunc{wxString
}{GetStringSelection
}{\void}
265 Gets the selected string - for single selection list boxes only. This
266 must be copied by the calling program if long term use is to be made of
271 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
272 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
},
\rtfsp
273 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
275 \membersection{wxListBox::InsertItems
}\label{wxlistboxinsertitems
}
277 \func{void
}{InsertItems
}{\param{int
}{ nItems
},
\param{const wxString
}{ items
},
\param{int
}{ pos
}}
279 Insert the given number of strings before the specified position.
281 \wxheading{Parameters
}
283 \docparam{nItems
}{Number of items in the array
{\it items
}}
285 \docparam{items
}{Labels of items to be inserted
}
287 \docparam{pos
}{Position before which to insert the items: for example, if
{\it pos
} is
0 the items
288 will be inserted in the beginning of the listbox
}
290 \pythonnote{The first two parameters are collapsed into a single
291 parameter for wxPython, which is a list of strings.
}
293 \perlnote{In wxPerl there is just an array reference in place of
{\tt nItems
}
296 \membersection{wxListBox::Number
}\label{wxlistboxnumber
}
298 \constfunc{int
}{Number
}{\void}
300 Returns the number of items in the listbox.
302 \membersection{wxListBox::Selected
}\label{wxlistboxselected
}
304 \constfunc{bool
}{Selected
}{\param{int
}{ n
}}
306 Determines whether an item is selected.
308 \wxheading{Parameters
}
310 \docparam{n
}{The zero-based item index.
}
312 \wxheading{Return value
}
314 TRUE if the given item is selected, FALSE otherwise.
316 \membersection{wxListBox::Set
}\label{wxlistboxset
}
318 \func{void
}{Set
}{\param{int
}{ n
},
\param{const wxString*
}{ choices
}}
320 Clears the list box and adds the given strings. Not implemented for GTK.
322 \wxheading{Parameters
}
324 \docparam{n
}{The number of strings to set.
}
326 \docparam{choices
}{An array of strings to set.
}
330 Deallocate the array from the calling program
331 after this function has been called.
333 \membersection{wxListBox::SetClientData
}\label{wxlistboxsetclientdata
}
335 \func{void
}{SetClientData
}{\param{int
}{ n
},
\param{void*
}{data
}}
337 Associates the given client data pointer with the given item.
339 \wxheading{Parameters
}
341 \docparam{n
}{The zero-based item index.
}
343 \docparam{data
}{The client data to associate with the item.
}
345 \membersection{wxListBox::SetFirstItem
}\label{wxlistboxsetfirstitem
}
347 \func{void
}{SetFirstItem
}{\param{int
}{ n
}}
349 \func{void
}{SetFirstItem
}{\param{const wxString\&
}{string
}}
351 Set the specified item to be the first visible item. Windows only.
353 \wxheading{Parameters
}
355 \docparam{n
}{The zero-based item index.
}
357 \docparam{string
}{The string that should be visible.
}
359 \membersection{wxListBox::SetSelection
}\label{wxlistboxsetselection
}
361 \func{void
}{SetSelection
}{\param{int
}{ n
},
\param{const bool
}{select = TRUE
}}
363 Selects or deselects the given item. This does not cause a
364 wxEVT
\_COMMAND\_LISTBOX\_SELECT event to get emitted.
366 \wxheading{Parameters
}
368 \docparam{n
}{The zero-based item index.
}
370 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}
372 \membersection{wxListBox::SetString
}\label{wxlistboxsetstring
}
374 \func{void
}{SetString
}{\param{int
}{ n
},
\param{const wxString\&
}{ string
}}
376 Sets the string value of an item.
378 \wxheading{Parameters
}
380 \docparam{n
}{The zero-based item index.
}
382 \docparam{string
}{The string to set.
}
384 \membersection{wxListBox::SetStringSelection
}\label{wxlistboxsetstringselection
}
386 \func{void
}{SetStringSelection
}{\param{const wxString\&
}{ string
},
\param{const bool
}{ select = TRUE
}}
388 Sets the current selection. This does not cause a
389 wxEVT
\_COMMAND\_LISTBOX\_SELECT event to get emitted.
391 \wxheading{Parameters
}
393 \docparam{string
}{The item to select.
}
395 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}