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. No effect for GTK.
}
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
105 \membersection{wxListBox::
\destruct{wxListBox
}}
107 \func{void
}{\destruct{wxListBox
}}{\void}
109 Destructor, destroying the list box.
111 \membersection{wxListBox::Append
}\label{wxlistboxappend
}
113 \func{void
}{Append
}{\param{const wxString\&
}{ item
}}
115 Adds the item to the end of the list box.
117 \func{void
}{Append
}{\param{const wxString\&
}{ item
},
\param{void*
}{clientData
}}
119 Adds the item to the end of the list box, associating the given data
122 \wxheading{Parameters
}
124 \docparam{item
}{String to add.
}
126 \docparam{clientData
}{Client data to associate with the item.
}
128 \membersection{wxListBox::Clear
}\label{wxlistboxclear
}
130 \func{void
}{Clear
}{\void}
132 Clears all strings from the list box.
134 \membersection{wxListBox::Create
}\label{wxlistboxcreate
}
136 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
137 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
138 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
139 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
141 Creates the listbox for two-step construction. See
\helpref{wxListBox::wxListBox
}{wxlistboxconstr
}\rtfsp
144 \membersection{wxListBox::Delete
}\label{wxlistboxdelete
}
146 \func{void
}{Delete
}{\param{int
}{ n
}}
148 Deletes an item from the listbox.
150 \wxheading{Parameters
}
152 \docparam{n
}{The zero-based item index.
}
154 \membersection{wxListBox::Deselect
}\label{wxlistboxdeselect
}
156 \func{void
}{Deselect
}{\param{int
}{ n
}}
158 Deselects an item in the list box.
160 \wxheading{Parameters
}
162 \docparam{n
}{The zero-based item to deselect.
}
166 This applies to multiple selection listboxes only.
168 \membersection{wxListBox::FindString
}\label{wxlistboxfindstring
}
170 \func{int
}{FindString
}{\param{const wxString\&
}{string
}}
172 Finds an item matching the given string.
174 \wxheading{Parameters
}
176 \docparam{string
}{String to find.
}
178 \wxheading{Return value
}
180 The zero-based position of the item, or -
1 if the string was not found.
182 \membersection{wxListBox::GetClientData
}\label{wxlistboxgetclientdata
}
184 \constfunc{void*
}{GetClientData
}{\param{int
}{ n
}}
186 Returns a pointer to the client data associated with the given item (if any).
188 \wxheading{Parameters
}
190 \docparam{n
}{The zero-based position of the item.
}
192 \wxheading{Return value
}
194 A pointer to the client data, or NULL if not present.
196 \membersection{wxListBox::GetSelection
}\label{wxlistboxgetselection
}
198 \constfunc{int
}{GetSelection
}{\void}
200 Gets the position of the selected item.
202 \wxheading{Return value
}
204 The position of the current selection.
208 Applicable to single selection list boxes only.
212 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
},
\rtfsp
213 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
214 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
}
216 \membersection{wxListBox::GetSelections
}\label{wxlistboxgetselections
}
218 \constfunc{int
}{GetSelections
}{\param{wxArrayInt\&
}{selections
}}
220 Fill an array of ints with the positions of the currently selected items.
222 \wxheading{Parameters
}
224 \docparam{selections
}{A reference to an wxArrayInt instance that is used to store the result of the query.
}
226 \wxheading{Return value
}
228 The number of selections.
232 Use this with a multiple selection listbox.
236 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
237 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
238 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
240 \pythonnote{The wxPython version of this method takes no parameters
241 and returns a tuple of the selected items.
}
243 \membersection{wxListBox::GetString
}\label{wxlistboxgetstring
}
245 \constfunc{wxString
}{GetString
}{\param{int
}{ n
}}
247 Returns the string at the given position.
249 \wxheading{Parameters
}
251 \docparam{n
}{The zero-based position.
}
253 \wxheading{Return value
}
255 The string, or an empty string if the position was invalid.
257 \membersection{wxListBox::GetStringSelection
}\label{wxlistboxgetstringselection
}
259 \constfunc{wxString
}{GetStringSelection
}{\void}
261 Gets the selected string - for single selection list boxes only. This
262 must be copied by the calling program if long term use is to be made of
267 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
268 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
},
\rtfsp
269 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
271 \membersection{wxListBox::InsertItems
}\label{wxlistboxinsertitems
}
273 \func{void
}{InsertItems
}{\param{int
}{ nItems
},
\param{const wxString
}{ items
},
\param{int
}{ pos
}}
275 Insert the given number of strings before the specified position.
277 \wxheading{Parameters
}
279 \docparam{nItems
}{Number of items in the array
{\it items
}}
281 \docparam{items
}{Labels of items to be inserted
}
283 \docparam{pos
}{Position before which to insert the items: for example, if
{\it pos
} is
0 the items
284 will be inserted in the beginning of the listbox
}
286 \pythonnote{The first two parameters are collapsed into a single
287 parameter for wxPython, which is a list of strings.
}
289 \membersection{wxListBox::Number
}\label{wxlistboxnumber
}
291 \constfunc{int
}{Number
}{\void}
293 Returns the number of items in the listbox.
295 \membersection{wxListBox::Selected
}\label{wxlistboxselected
}
297 \constfunc{bool
}{Selected
}{\param{int
}{ n
}}
299 Determines whether an item is selected.
301 \wxheading{Parameters
}
303 \docparam{n
}{The zero-based item index.
}
305 \wxheading{Return value
}
307 TRUE if the given item is selected, FALSE otherwise.
309 \membersection{wxListBox::Set
}\label{wxlistboxset
}
311 \func{void
}{Set
}{\param{int
}{ n
},
\param{const wxString*
}{ choices
}}
313 Clears the list box and adds the given strings. Not implemented for GTK.
315 \wxheading{Parameters
}
317 \docparam{n
}{The number of strings to set.
}
319 \docparam{choices
}{An array of strings to set.
}
323 Deallocate the array from the calling program
324 after this function has been called.
326 \membersection{wxListBox::SetClientData
}\label{wxlistboxsetclientdata
}
328 \func{void
}{SetClientData
}{\param{int
}{ n
},
\param{void*
}{data
}}
330 Associates the given client data pointer with the given item.
332 \wxheading{Parameters
}
334 \docparam{n
}{The zero-based item index.
}
336 \docparam{data
}{The client data to associate with the item.
}
338 \membersection{wxListBox::SetFirstItem
}\label{wxlistboxsetfirstitem
}
340 \func{void
}{SetFirstItem
}{\param{int
}{ n
}}
342 \func{void
}{SetFirstItem
}{\param{const wxString\&
}{string
}}
344 Set the specified item to be the first visible item. Windows only.
346 \wxheading{Parameters
}
348 \docparam{n
}{The zero-based item index.
}
350 \docparam{string
}{The string that should be visible.
}
352 \membersection{wxListBox::SetSelection
}\label{wxlistboxsetselection
}
354 \func{void
}{SetSelection
}{\param{int
}{ n
},
\param{const bool
}{select = TRUE
}}
356 Selects or deselects the given item. This does not cause a
357 wxEVT
\_COMMAND\_LISTBOX\_SELECT event to get emitted.
359 \wxheading{Parameters
}
361 \docparam{n
}{The zero-based item index.
}
363 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}
365 \membersection{wxListBox::SetString
}\label{wxlistboxsetstring
}
367 \func{void
}{SetString
}{\param{int
}{ n
},
\param{const wxString\&
}{ string
}}
369 Sets the string value of an item.
371 \wxheading{Parameters
}
373 \docparam{n
}{The zero-based item index.
}
375 \docparam{string
}{The string to set.
}
377 \membersection{wxListBox::SetStringSelection
}\label{wxlistboxsetstringselection
}
379 \func{void
}{SetStringSelection
}{\param{const wxString\&
}{ string
},
\param{const bool
}{ select = TRUE
}}
381 Sets the current selection. This does not cause a
382 wxEVT
\_COMMAND\_LISTBOX\_SELECT event to get emitted.
384 \wxheading{Parameters
}
386 \docparam{string
}{The item to select.
}
388 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}