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
}.
41 \helpref{wxChoice
}{wxchoice
},
\helpref{wxComboBox
}{wxcombobox
},
\helpref{wxListCtrl
}{wxlistctrl
}
43 \latexignore{\rtfignore{\wxheading{Members
}}}
45 \membersection{wxListBox::wxListBox
}\label{wxlistboxconstr
}
47 \func{}{wxListBox
}{\void}
51 \func{}{wxListBox
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
52 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
53 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
54 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
56 Constructor, creating and showing a list box.
58 \wxheading{Parameters
}
60 \docparam{parent
}{Parent window. Must not be NULL.
}
62 \docparam{id
}{Window identifier. A value of -
1 indicates a default value.
}
64 \docparam{pos
}{Window position.
}
66 \docparam{size
}{Window size. If the default size (-
1, -
1) is specified then the window is sized
69 \docparam{n
}{Number of strings with which to initialise the control.
}
71 \docparam{choices
}{An array of strings with which to initialise the control.
}
73 \docparam{style
}{Window style. See
\helpref{wxListBox
}{wxlistbox
}.
}
75 \docparam{validator
}{Window validator.
}
77 \docparam{name
}{Window name.
}
81 \helpref{wxListBox::Create
}{wxlistboxcreate
},
\helpref{wxValidator
}{wxvalidator
}
83 \membersection{wxListBox::
\destruct{wxListBox
}}
85 \func{void
}{\destruct{wxListBox
}}{\void}
87 Destructor, destroying the list box.
89 \membersection{wxListBox::Append
}\label{wxlistboxappend
}
91 \func{void
}{Append
}{\param{const wxString\&
}{ item
}}
93 Adds the item to the end of the list box.
95 \func{void
}{Append
}{\param{const wxString\&
}{ item
},
\param{char*
}{clientData
}}
97 Adds the item to the end of the list box, associating the given data
100 \wxheading{Parameters
}
102 \docparam{item
}{String to add.
}
104 \docparam{clientData
}{Client data to associate with the item.
}
106 \membersection{wxListBox::Clear
}\label{wxlistboxclear
}
108 \func{void
}{Clear
}{\void}
110 Clears all strings from the list box.
112 \membersection{wxListBox::Create
}\label{wxlistboxcreate
}
114 \func{bool
}{Create
}{\param{wxWindow*
}{ parent
},
\param{wxWindowID
}{ id
},
\rtfsp
115 \param{const wxPoint\&
}{ pos = wxDefaultPosition
},
\param{const wxSize\&
}{ size = wxDefaultSize
},
\rtfsp
116 \param{int
}{ n
},
\param{const wxString
}{choices
[] = NULL
},
\rtfsp
117 \param{long
}{ style =
0},
\param{const wxValidator\&
}{validator = wxDefaultValidator
},
\param{const wxString\&
}{name = ``listBox"
}}
119 Creates the listbox for two-step construction. See
\helpref{wxListBox::wxListBox
}{wxlistboxconstr
}\rtfsp
122 \membersection{wxListBox::Delete
}\label{wxlistboxdelete
}
124 \func{void
}{Delete
}{\param{int
}{ n
}}
126 Deletes an item from the listbox.
128 \wxheading{Parameters
}
130 \docparam{n
}{The zero-based item index.
}
132 \membersection{wxListBox::Deselect
}\label{wxlistboxdeselect
}
134 \func{void
}{Deselect
}{\param{int
}{ n
}}
136 Deselects an item in the list box.
138 \wxheading{Parameters
}
140 \docparam{n
}{The zero-based item to deselect.
}
144 This applies to multiple selection listboxes only.
146 \membersection{wxListBox::FindString
}\label{wxlistboxfindstring
}
148 \func{int
}{FindString
}{\param{const wxString\&
}{string
}}
150 Finds an item matching the given string.
152 \wxheading{Parameters
}
154 \docparam{string
}{String to find.
}
156 \wxheading{Return value
}
158 The zero-based position of the item, or -
1 if the string was not found.
160 \membersection{wxListBox::GetClientData
}\label{wxlistboxgetclientdata
}
162 \constfunc{char*
}{GetClientData
}{\param{int
}{ n
}}
164 Returns a pointer to the client data associated with the given item (if any).
166 \wxheading{Parameters
}
168 \docparam{n
}{The zero-based position of the item.
}
170 \wxheading{Return value
}
172 A pointer to the client data, or NULL if not present.
174 \membersection{wxListBox::GetSelection
}\label{wxlistboxgetselection
}
176 \constfunc{int
}{GetSelection
}{\void}
178 Gets the position of the selected item.
180 \wxheading{Return value
}
182 The position of the current selection.
186 Applicable to single selection list boxes only.
190 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
},
\rtfsp
191 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
192 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
}
194 \membersection{wxListBox::GetSelections
}\label{wxlistboxgetselections
}
196 \constfunc{int
}{GetSelections
}{\param{int **
}{selections
}}
198 Gets an array containing the positions of the selected strings.
200 \wxheading{Parameters
}
202 \docparam{selections
}{A pointer to an integer array, which will be allocated by the function if
203 selects are present. Do not deallocate the returned array - it will be deallocated by the listbox.
}
205 \wxheading{Return value
}
207 The number of selections.
211 Use this with a multiple selection listbox.
215 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
216 \helpref{wxListBox::GetStringSelection
}{wxlistboxgetstringselection
},
\rtfsp
217 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
219 \membersection{wxListBox::GetString
}\label{wxlistboxgetstring
}
221 \constfunc{wxString
}{GetString
}{\param{int
}{ n
}}
223 Returns the string at the given position.
225 \wxheading{Parameters
}
227 \docparam{n
}{The zero-based position.
}
229 \wxheading{Return value
}
231 The string, or an empty string if the position was invalid.
233 \membersection{wxListBox::GetStringSelection
}\label{wxlistboxgetstringselection
}
235 \constfunc{wxString
}{GetStringSelection
}{\void}
237 Gets the selected string - for single selection list boxes only. This
238 must be copied by the calling program if long term use is to be made of
243 \helpref{wxListBox::GetSelection
}{wxlistboxgetselection
},
\rtfsp
244 \helpref{wxListBox::GetSelections
}{wxlistboxgetselections
},
\rtfsp
245 \helpref{wxListBox::SetSelection
}{wxlistboxsetselection
}
247 \membersection{wxListBox::Number
}\label{wxlistboxnumber
}
249 \constfunc{int
}{Number
}{\void}
251 Returns the number of items in the listbox.
253 \membersection{wxListBox::Selected
}\label{wxlistboxselected
}
255 \constfunc{bool
}{Selected
}{\param{int
}{ n
}}
257 Determines whether an item is selected.
259 \wxheading{Parameters
}
261 \docparam{n
}{The zero-based item index.
}
263 \wxheading{Return value
}
265 TRUE if the given item is selected, FALSE otherwise.
267 \membersection{wxListBox::Set
}\label{wxlistboxset
}
269 \func{void
}{Set
}{\param{int
}{ n
},
\param{const wxString*
}{ choices
}}
271 Clears the list box and adds the given strings.
273 \wxheading{Parameters
}
275 \docparam{n
}{The number of strings to set.
}
277 \docparam{choices
}{An array of strings to set.
}
281 Deallocate the array from the calling program
282 after this function has been called.
284 \membersection{wxListBox::SetClientData
}\label{wxlistboxsetclientdata
}
286 \func{void
}{SetClientData
}{\param{int
}{ n
},
\param{char*
}{data
}}
288 Associates the given client data pointer with the given item.
290 \wxheading{Parameters
}
292 \docparam{n
}{The zero-based item index.
}
294 \docparam{data
}{The client data to associate with the item.
}
296 \membersection{wxListBox::SetFirstItem
}\label{wxlistboxsetfirstitem
}
298 \func{void
}{SetFirstItem
}{\param{int
}{ n
}}
300 \func{void
}{SetFirstItem
}{\param{const wxString\&
}{string
}}
302 Set the specified item to be the first visible item.
304 \wxheading{Parameters
}
306 \docparam{n
}{The zero-based item index.
}
308 \docparam{string
}{The string that should be visible.
}
310 \membersection{wxListBox::SetSelection
}\label{wxlistboxsetselection
}
312 \func{void
}{SetSelection
}{\param{int
}{ n
},
\param{const bool
}{select = TRUE
}}
314 Selects or deselects the given item.
316 \wxheading{Parameters
}
318 \docparam{n
}{The zero-based item index.
}
320 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}
322 \membersection{wxListBox::SetString
}\label{wxlistboxsetstring
}
324 \func{void
}{SetString
}{\param{int
}{ n
},
\param{const wxString\&
}{ string
}}
326 Sets the string value of an item.
328 \wxheading{Parameters
}
330 \docparam{n
}{The zero-based item index.
}
332 \docparam{string
}{The string to set.
}
334 \membersection{wxListBox::SetStringSelection
}\label{wxlistboxsetstringselection
}
336 \func{void
}{SetStringSelection
}{\param{const wxString\&
}{ string
},
\param{const bool
}{ select = TRUE
}}
338 Sets the current selection.
340 \wxheading{Parameters
}
342 \docparam{string
}{The item to select.
}
344 \docparam{select
}{If TRUE, will select the item. If FALSE, will deselect it.
}