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{Window styles
}
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
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.
}
37 See also
\helpref{window styles overview
}{windowstyles
}.
39 \wxheading{Event handling
}
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.
}
45 \twocolitem{{\bf EVT
\_LISTBOX\_DCLICK(id, func)
}}{Process a wxEVT
\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
46 when the listbox is doubleclicked.
}
51 \helpref{wxChoice
}{wxchoice
},
\helpref{wxComboBox
}{wxcombobox
},
\helpref{wxListCtrl
}{wxlistctrl
},
52 \rtfsp\helpref{wxCommandEvent
}{wxcommandevent
}
54 \latexignore{\rtfignore{\wxheading{Members
}}}
56 \membersection{wxListBox::wxListBox
}\label{wxlistboxconstr
}
58 \func{}{wxListBox
}{\void}
62 \func{}{wxListBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
63 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
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"
}}
67 Constructor, creating and showing a list box.
69 \wxheading{Parameters
}
71 \docparam{parent
}{Parent window. Must not be NULL.
}
73 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
75 \docparam{pos
}{Window position.
}
77 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
80 \docparam{n
}{Number of strings with which to initialise the control.
}
82 \docparam{choices
}{An array of strings with which to initialise the control.
}
84 \docparam{style
}{Window style. See
\helpref{wxListBox
}{wxlistbox
}.
}
86 \docparam{validator
}{Window validator.
}
88 \docparam{name
}{Window name.
}
92 \helpref{wxListBox::Create
}{wxlistboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
94 \membersection{wxListBox::
\destruct{wxListBox
}}
96 \func{void
}{\destruct{wxListBox
}}{\void}
98 Destructor, destroying the list box.
100 \membersection{wxListBox::Append
}\label{wxlistboxappend
}
102 \func{void
}{Append
}{\param{const wxString\&
}{ item
}}
104 Adds the item to the end of the list box.
106 \func{void
}{Append
}{\param{const wxString\&
}{ item
},
\param{char*
}{clientData
}}
108 Adds the item to the end of the list box, associating the given data
111 \wxheading{Parameters
}
113 \docparam{item
}{String to add.
}
115 \docparam{clientData
}{Client data to associate with the item.
}
117 \membersection{wxListBox::Clear
}\label{wxlistboxclear
}
119 \func{void
}{Clear
}{\void}
121 Clears all strings from the list box.
123 \membersection{wxListBox::Create
}\label{wxlistboxcreate
}
125 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
126 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
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"
}}
130 Creates the listbox for two-step construction. See
\helpref{wxListBox::wxListBox
}{wxlistboxconstr
}\rtfsp
133 \membersection{wxListBox::Delete
}\label{wxlistboxdelete
}
135 \func{void
}{Delete
}{\param{int
}{ n
}}
137 Deletes an item from the listbox.
139 \wxheading{Parameters
}
141 \docparam{n
}{The zero-based item index.
}
143 \membersection{wxListBox::Deselect
}\label{wxlistboxdeselect
}
145 \func{void
}{Deselect
}{\param{int
}{ n
}}
147 Deselects an item in the list box.
149 \wxheading{Parameters
}
151 \docparam{n
}{The zero-based item to deselect.
}
155 This applies to multiple selection listboxes only.
157 \membersection{wxListBox::FindString
}\label{wxlistboxfindstring
}
159 \func{int
}{FindString
}{\param{const wxString\&
}{string
}}
161 Finds an item matching the given string.
163 \wxheading{Parameters
}
165 \docparam{string
}{String to find.
}
167 \wxheading{Return value
}
169 The zero-based position of the item, or -
1 if the string was not found.
171 \membersection{wxListBox::GetClientData
}\label{wxlistboxgetclientdata
}
173 \constfunc{char*
}{GetClientData
}{\param{int
}{ n
}}
175 Returns a pointer to the client data associated with the given item (if any).
177 \wxheading{Parameters
}
179 \docparam{n
}{The zero-based position of the item.
}
181 \wxheading{Return value
}
183 A pointer to the client data, or NULL if not present.
185 \membersection{wxListBox::GetSelection
}\label{wxlistboxgetselection
}
187 \constfunc{int
}{GetSelection
}{\void}
189 Gets the position of the selected item.
191 \wxheading{Return value
}
193 The position of the current selection.
197 Applicable to single selection list boxes only.
201 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
},
\rtfsp
202 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
203 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
}
205 \membersection{wxListBox::GetSelections
}\label{wxlistboxgetselections
}
207 \constfunc{int
}{GetSelections
}{\param{int **
}{selections
}}
209 Gets an array containing the positions of the selected strings.
211 \wxheading{Parameters
}
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.
}
216 \wxheading{Return value
}
218 The number of selections.
222 Use this with a multiple selection listbox.
226 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
227 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
228 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
230 \membersection{wxListBox::GetString
}\label{wxlistboxgetstring
}
232 \constfunc{wxString
}{GetString
}{\param{int
}{ n
}}
234 Returns the string at the given position.
236 \wxheading{Parameters
}
238 \docparam{n
}{The zero-based position.
}
240 \wxheading{Return value
}
242 The string, or an empty string if the position was invalid.
244 \membersection{wxListBox::GetStringSelection
}\label{wxlistboxgetstringselection
}
246 \constfunc{wxString
}{GetStringSelection
}{\void}
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
254 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
255 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
},
\rtfsp
256 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
258 \membersection{wxListBox::Number
}\label{wxlistboxnumber
}
260 \constfunc{int
}{Number
}{\void}
262 Returns the number of items in the listbox.
264 \membersection{wxListBox::Selected
}\label{wxlistboxselected
}
266 \constfunc{bool
}{Selected
}{\param{int
}{ n
}}
268 Determines whether an item is selected.
270 \wxheading{Parameters
}
272 \docparam{n
}{The zero-based item index.
}
274 \wxheading{Return value
}
276 TRUE if the given item is selected, FALSE otherwise.
278 \membersection{wxListBox::Set
}\label{wxlistboxset
}
280 \func{void
}{Set
}{\param{int
}{ n
},
\param{const wxString*
}{ choices
}}
282 Clears the list box and adds the given strings.
284 \wxheading{Parameters
}
286 \docparam{n
}{The number of strings to set.
}
288 \docparam{choices
}{An array of strings to set.
}
292 Deallocate the array from the calling program
293 after this function has been called.
295 \membersection{wxListBox::SetClientData
}\label{wxlistboxsetclientdata
}
297 \func{void
}{SetClientData
}{\param{int
}{ n
},
\param{char*
}{data
}}
299 Associates the given client data pointer with the given item.
301 \wxheading{Parameters
}
303 \docparam{n
}{The zero-based item index.
}
305 \docparam{data
}{The client data to associate with the item.
}
307 \membersection{wxListBox::SetFirstItem
}\label{wxlistboxsetfirstitem
}
309 \func{void
}{SetFirstItem
}{\param{int
}{ n
}}
311 \func{void
}{SetFirstItem
}{\param{const wxString\&
}{string
}}
313 Set the specified item to be the first visible item.
315 \wxheading{Parameters
}
317 \docparam{n
}{The zero-based item index.
}
319 \docparam{string
}{The string that should be visible.
}
321 \membersection{wxListBox::SetSelection
}\label{wxlistboxsetselection
}
323 \func{void
}{SetSelection
}{\param{int
}{ n
},
\param{const bool
}{select = TRUE
}}
325 Selects or deselects the given item.
327 \wxheading{Parameters
}
329 \docparam{n
}{The zero-based item index.
}
331 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}
333 \membersection{wxListBox::SetString
}\label{wxlistboxsetstring
}
335 \func{void
}{SetString
}{\param{int
}{ n
},
\param{const wxString\&
}{ string
}}
337 Sets the string value of an item.
339 \wxheading{Parameters
}
341 \docparam{n
}{The zero-based item index.
}
343 \docparam{string
}{The string to set.
}
345 \membersection{wxListBox::SetStringSelection
}\label{wxlistboxsetstringselection
}
347 \func{void
}{SetStringSelection
}{\param{const wxString\&
}{ string
},
\param{const bool
}{ select = TRUE
}}
349 Sets the current selection.
351 \wxheading{Parameters
}
353 \docparam{string
}{The item to select.
}
355 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}