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.
12 A listbox callback gets an event wxEVT
\_COMMAND\_LISTBOX\_SELECT for single clicks, and
13 wxEVT
\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
15 \wxheading{Derived from
}
17 \helpref{wxControl
}{wxcontrol
}\\
18 \helpref{wxWindow
}{wxwindow
}\\
19 \helpref{wxEvtHandler
}{wxevthandler
}\\
20 \helpref{wxObject
}{wxobject
}
22 \wxheading{Include files
}
26 \wxheading{Window styles
}
29 \begin{twocollist
}\itemsep=
0pt
30 \twocolitem{\windowstyle{wxLB
\_SINGLE}}{Single-selection list.
}
31 \twocolitem{\windowstyle{wxLB
\_MULTIPLE}}{Multiple-selection list: the user can toggle multiple
33 \twocolitem{\windowstyle{wxLB
\_EXTENDED}}{Extended-selection list: the user can
34 select multiple items using the SHIFT key and the mouse or special key combinations.
}
35 \twocolitem{\windowstyle{wxLB
\_HSCROLL}}{Create horizontal scrollbar if contents are too wide (Windows only).
}
36 \twocolitem{\windowstyle{wxLB
\_ALWAYS\_SB}}{Always show a vertical scrollbar.
}
37 \twocolitem{\windowstyle{wxLB
\_NEEDED\_SB}}{Only create a vertical scrollbar if needed.
}
38 \twocolitem{\windowstyle{wxLB
\_SORT}}{The listbox contents are sorted in alphabetical order.
}
41 See also
\helpref{window styles overview
}{windowstyles
}.
43 \wxheading{Event handling
}
46 \begin{twocollist
}\itemsep=
0pt
47 \twocolitem{{\bf EVT
\_LISTBOX(id, func)
}}{Process a wxEVT
\_COMMAND\_LISTBOX\_SELECTED event,
48 when an item on the list is selected.
}
49 \twocolitem{{\bf EVT
\_LISTBOX\_DCLICK(id, func)
}}{Process a wxEVT
\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
50 when the listbox is doubleclicked.
}
55 \helpref{wxChoice
}{wxchoice
},
\helpref{wxComboBox
}{wxcombobox
},
\helpref{wxListCtrl
}{wxlistctrl
},
56 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
58 \latexignore{\rtfignore{\wxheading{Members
}}}
60 \membersection{wxListBox::wxListBox
}\label{wxlistboxconstr
}
62 \func{}{wxListBox
}{\void}
66 \func{}{wxListBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
67 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
68 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
69 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
71 Constructor, creating and showing a list box.
73 \wxheading{Parameters
}
75 \docparam{parent
}{Parent window. Must not be NULL.
}
77 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
79 \docparam{pos
}{Window position.
}
81 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
84 \docparam{n
}{Number of strings with which to initialise the control.
}
86 \docparam{choices
}{An array of strings with which to initialise the control.
}
88 \docparam{style
}{Window style. See
\helpref{wxListBox
}{wxlistbox
}.
}
90 \docparam{validator
}{Window validator.
}
92 \docparam{name
}{Window name.
}
96 \helpref{wxListBox::Create
}{wxlistboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
98 \pythonnote{The wxListBox constructor in wxPython reduces the
\tt{n
}
99 and
\tt{choices
} arguments are to a single argument, which is
104 \membersection{wxListBox::
\destruct{wxListBox
}}
106 \func{void
}{\destruct{wxListBox
}}{\void}
108 Destructor, destroying the list box.
110 \membersection{wxListBox::Append
}\label{wxlistboxappend
}
112 \func{void
}{Append
}{\param{const wxString\&
}{ item
}}
114 Adds the item to the end of the list box.
116 \func{void
}{Append
}{\param{const wxString\&
}{ item
},
\param{char*
}{clientData
}}
118 Adds the item to the end of the list box, associating the given data
121 \wxheading{Parameters
}
123 \docparam{item
}{String to add.
}
125 \docparam{clientData
}{Client data to associate with the item.
}
127 \membersection{wxListBox::Clear
}\label{wxlistboxclear
}
129 \func{void
}{Clear
}{\void}
131 Clears all strings from the list box.
133 \membersection{wxListBox::Create
}\label{wxlistboxcreate
}
135 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
136 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
137 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
138 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
140 Creates the listbox for two-step construction. See
\helpref{wxListBox::wxListBox
}{wxlistboxconstr
}\rtfsp
143 \membersection{wxListBox::Delete
}\label{wxlistboxdelete
}
145 \func{void
}{Delete
}{\param{int
}{ n
}}
147 Deletes an item from the listbox.
149 \wxheading{Parameters
}
151 \docparam{n
}{The zero-based item index.
}
153 \membersection{wxListBox::Deselect
}\label{wxlistboxdeselect
}
155 \func{void
}{Deselect
}{\param{int
}{ n
}}
157 Deselects an item in the list box.
159 \wxheading{Parameters
}
161 \docparam{n
}{The zero-based item to deselect.
}
165 This applies to multiple selection listboxes only.
167 \membersection{wxListBox::FindString
}\label{wxlistboxfindstring
}
169 \func{int
}{FindString
}{\param{const wxString\&
}{string
}}
171 Finds an item matching the given string.
173 \wxheading{Parameters
}
175 \docparam{string
}{String to find.
}
177 \wxheading{Return value
}
179 The zero-based position of the item, or -
1 if the string was not found.
181 \membersection{wxListBox::GetClientData
}\label{wxlistboxgetclientdata
}
183 \constfunc{char*
}{GetClientData
}{\param{int
}{ n
}}
185 Returns a pointer to the client data associated with the given item (if any).
187 \wxheading{Parameters
}
189 \docparam{n
}{The zero-based position of the item.
}
191 \wxheading{Return value
}
193 A pointer to the client data, or NULL if not present.
195 \membersection{wxListBox::GetSelection
}\label{wxlistboxgetselection
}
197 \constfunc{int
}{GetSelection
}{\void}
199 Gets the position of the selected item.
201 \wxheading{Return value
}
203 The position of the current selection.
207 Applicable to single selection list boxes only.
211 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
},
\rtfsp
212 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
213 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
}
215 \membersection{wxListBox::GetSelections
}\label{wxlistboxgetselections
}
217 \constfunc{int
}{GetSelections
}{\param{int **
}{selections
}}
219 Gets an array containing the positions of the selected strings.
221 \wxheading{Parameters
}
223 \docparam{selections
}{A pointer to an integer array, which will be allocated by the function if
224 selects are present. Do not deallocate the returned array - it will be deallocated by the listbox.
}
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 \membersection{wxListBox::GetString
}\label{wxlistboxgetstring
}
242 \constfunc{wxString
}{GetString
}{\param{int
}{ n
}}
244 Returns the string at the given position.
246 \wxheading{Parameters
}
248 \docparam{n
}{The zero-based position.
}
250 \wxheading{Return value
}
252 The string, or an empty string if the position was invalid.
254 \membersection{wxListBox::GetStringSelection
}\label{wxlistboxgetstringselection
}
256 \constfunc{wxString
}{GetStringSelection
}{\void}
258 Gets the selected string - for single selection list boxes only. This
259 must be copied by the calling program if long term use is to be made of
264 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
265 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
},
\rtfsp
266 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
268 \membersection{wxListBox::InsertItems
}\label{wxlistboxinsertitems
}
270 \func{void
}{InsertItems
}{\param{int
}{ nItems
},
\param{const wxString
}{ items
},
\param{int
}{ pos
}}
272 Insert the given number of strings before the specified position.
274 \wxheading{Parameters
}
276 \docparam{nItems
}{Number of items in the array
{\it items
}}
278 \docparam{items
}{Labels of items to be inserted
}
280 \docparam{pos
}{Position before which to insert the items: for example, if
{\it pos
} is
0 the items
281 will be inserted in the beginning of the listbox
}
283 \membersection{wxListBox::Number
}\label{wxlistboxnumber
}
285 \constfunc{int
}{Number
}{\void}
287 Returns the number of items in the listbox.
289 \membersection{wxListBox::Selected
}\label{wxlistboxselected
}
291 \constfunc{bool
}{Selected
}{\param{int
}{ n
}}
293 Determines whether an item is selected.
295 \wxheading{Parameters
}
297 \docparam{n
}{The zero-based item index.
}
299 \wxheading{Return value
}
301 TRUE if the given item is selected, FALSE otherwise.
303 \membersection{wxListBox::Set
}\label{wxlistboxset
}
305 \func{void
}{Set
}{\param{int
}{ n
},
\param{const wxString*
}{ choices
}}
307 Clears the list box and adds the given strings.
309 \wxheading{Parameters
}
311 \docparam{n
}{The number of strings to set.
}
313 \docparam{choices
}{An array of strings to set.
}
317 Deallocate the array from the calling program
318 after this function has been called.
320 \membersection{wxListBox::SetClientData
}\label{wxlistboxsetclientdata
}
322 \func{void
}{SetClientData
}{\param{int
}{ n
},
\param{char*
}{data
}}
324 Associates the given client data pointer with the given item.
326 \wxheading{Parameters
}
328 \docparam{n
}{The zero-based item index.
}
330 \docparam{data
}{The client data to associate with the item.
}
332 \membersection{wxListBox::SetFirstItem
}\label{wxlistboxsetfirstitem
}
334 \func{void
}{SetFirstItem
}{\param{int
}{ n
}}
336 \func{void
}{SetFirstItem
}{\param{const wxString\&
}{string
}}
338 Set the specified item to be the first visible item.
340 \wxheading{Parameters
}
342 \docparam{n
}{The zero-based item index.
}
344 \docparam{string
}{The string that should be visible.
}
346 \membersection{wxListBox::SetSelection
}\label{wxlistboxsetselection
}
348 \func{void
}{SetSelection
}{\param{int
}{ n
},
\param{const bool
}{select = TRUE
}}
350 Selects or deselects the given item.
352 \wxheading{Parameters
}
354 \docparam{n
}{The zero-based item index.
}
356 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}
358 \membersection{wxListBox::SetString
}\label{wxlistboxsetstring
}
360 \func{void
}{SetString
}{\param{int
}{ n
},
\param{const wxString\&
}{ string
}}
362 Sets the string value of an item.
364 \wxheading{Parameters
}
366 \docparam{n
}{The zero-based item index.
}
368 \docparam{string
}{The string to set.
}
370 \membersection{wxListBox::SetStringSelection
}\label{wxlistboxsetstringselection
}
372 \func{void
}{SetStringSelection
}{\param{const wxString\&
}{ string
},
\param{const bool
}{ select = TRUE
}}
374 Sets the current selection.
376 \wxheading{Parameters
}
378 \docparam{string
}{The item to select.
}
380 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}