]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/listbox.tex
better documentation for wxWindow::SetSizerAndFit()
[wxWidgets.git] / docs / latex / wx / listbox.tex
CommitLineData
a660d684
KB
1\section{\class{wxListBox}}\label{wxlistbox}
2
3A listbox is used to select one or more of a list of strings. The
4strings are displayed in a scrolling box, with the selected string(s)
5marked in reverse video. A listbox can be single selection (if an item
6is selected, the previous selection is removed) or multiple selection
7(clicking an item toggles the item on or off independently of other
8selections).
9
6a1fd44f
RR
10List box elements are numbered from zero. Their number may be limited
11under some platforms.
a660d684 12
80b1853f 13A listbox callback gets an event wxEVT\_COMMAND\_LISTBOX\_SELECTED for single clicks, and
debe6624 14wxEVT\_COMMAND\_LISTBOX\_DOUBLE\_CLICKED for double clicks.
a660d684
KB
15
16\wxheading{Derived from}
17
bed5584e 18\helpref{wxControlWithItems}{wxcontrolwithitems}\\
a660d684
KB
19\helpref{wxControl}{wxcontrol}\\
20\helpref{wxWindow}{wxwindow}\\
21\helpref{wxEvtHandler}{wxevthandler}\\
22\helpref{wxObject}{wxobject}
23
954b8ae6
JS
24\wxheading{Include files}
25
26<wx/listbox.h>
27
a7af285d
VZ
28\wxheading{Library}
29
30\helpref{wxCore}{librarieslist}
31
a660d684
KB
32\wxheading{Window styles}
33
34\twocolwidtha{5cm}%
35\begin{twocollist}\itemsep=0pt
36\twocolitem{\windowstyle{wxLB\_SINGLE}}{Single-selection list.}
37\twocolitem{\windowstyle{wxLB\_MULTIPLE}}{Multiple-selection list: the user can toggle multiple
38items on and off.}
39\twocolitem{\windowstyle{wxLB\_EXTENDED}}{Extended-selection list: the user can
40select multiple items using the SHIFT key and the mouse or special key combinations.}
41\twocolitem{\windowstyle{wxLB\_HSCROLL}}{Create horizontal scrollbar if contents are too wide (Windows only).}
42\twocolitem{\windowstyle{wxLB\_ALWAYS\_SB}}{Always show a vertical scrollbar.}
43\twocolitem{\windowstyle{wxLB\_NEEDED\_SB}}{Only create a vertical scrollbar if needed.}
3377b962 44\twocolitem{\windowstyle{wxLB\_SORT}}{The listbox contents are sorted in alphabetical order.}
a660d684
KB
45\end{twocollist}
46
54081dc5
VZ
47Note that {\tt wxLB\_SINGLE}, {\tt wxLB\_MULTIPLE} and {\tt wxLB\_EXTENDED}
48styles are mutually exclusive and you can specify at most one of them (single
49selection is the default).
50
a660d684
KB
51See also \helpref{window styles overview}{windowstyles}.
52
5de76427
JS
53\wxheading{Event handling}
54
55\twocolwidtha{7cm}
56\begin{twocollist}\itemsep=0pt
57\twocolitem{{\bf EVT\_LISTBOX(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_SELECTED event,
6a1fd44f 58when an item on the list is selected or the selection changes.}
def172b2 59\twocolitem{{\bf EVT\_LISTBOX\_DCLICK(id, func)}}{Process a wxEVT\_COMMAND\_LISTBOX\_DOUBLECLICKED event,
2edb0bde 60when the listbox is double-clicked.}
5de76427
JS
61\end{twocollist}
62
a660d684
KB
63\wxheading{See also}
64
5de76427
JS
65\helpref{wxChoice}{wxchoice}, \helpref{wxComboBox}{wxcombobox}, \helpref{wxListCtrl}{wxlistctrl},
66\rtfsp\helpref{wxCommandEvent}{wxcommandevent}
a660d684
KB
67
68\latexignore{\rtfignore{\wxheading{Members}}}
69
f0e8a2d0 70\membersection{wxListBox::wxListBox}\label{wxlistboxctor}
a660d684
KB
71
72\func{}{wxListBox}{\void}
73
74Default constructor.
75
eaaa6a06 76\func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 77\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
1219d8a4 78\param{int}{ n = 0}, \param{const wxString }{choices[] = NULL},\rtfsp
eaaa6a06 79\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
a660d684 80
56b88f12
MB
81\func{}{wxListBox}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
82\param{const wxPoint\&}{ pos}, \param{const wxSize\&}{ size},\rtfsp
83\param{const wxArrayString\& }{choices},\rtfsp
84\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
85
a660d684
KB
86Constructor, creating and showing a list box.
87
88\wxheading{Parameters}
89
90\docparam{parent}{Parent window. Must not be NULL.}
91
92\docparam{id}{Window identifier. A value of -1 indicates a default value.}
93
94\docparam{pos}{Window position.}
95
96\docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
97appropriately.}
98
99\docparam{n}{Number of strings with which to initialise the control.}
100
101\docparam{choices}{An array of strings with which to initialise the control.}
102
103\docparam{style}{Window style. See \helpref{wxListBox}{wxlistbox}.}
104
105\docparam{validator}{Window validator.}
106
107\docparam{name}{Window name.}
108
109\wxheading{See also}
110
111\helpref{wxListBox::Create}{wxlistboxcreate}, \helpref{wxValidator}{wxvalidator}
112
c9110876
VS
113\pythonnote{The wxListBox constructor in wxPython reduces the {\tt n}
114and {\tt choices} arguments are to a single argument, which is
06d20283
RD
115a list of strings.}
116
5873607e
VZ
117\perlnote{In wxPerl there is just an array reference in place of {\tt n}
118and {\tt choices}.}
06d20283 119
f0e8a2d0 120\membersection{wxListBox::\destruct{wxListBox}}\label{wxlistboxdtor}
a660d684
KB
121
122\func{void}{\destruct{wxListBox}}{\void}
123
124Destructor, destroying the list box.
125
a660d684
KB
126\membersection{wxListBox::Create}\label{wxlistboxcreate}
127
eaaa6a06 128\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
a660d684 129\param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
eaaa6a06
JS
130\param{int}{ n}, \param{const wxString }{choices[] = NULL},\rtfsp
131\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
a660d684 132
56b88f12
MB
133\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
134\param{const wxPoint\&}{ pos}, \param{const wxSize\&}{ size},\rtfsp
135\param{const wxArrayString\& }{choices},\rtfsp
136\param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``listBox"}}
137
f0e8a2d0 138Creates the listbox for two-step construction. See \helpref{wxListBox::wxListBox}{wxlistboxctor}\rtfsp
a660d684
KB
139for further details.
140
a660d684
KB
141\membersection{wxListBox::Deselect}\label{wxlistboxdeselect}
142
143\func{void}{Deselect}{\param{int}{ n}}
144
145Deselects an item in the list box.
146
147\wxheading{Parameters}
148
149\docparam{n}{The zero-based item to deselect.}
150
151\wxheading{Remarks}
152
153This applies to multiple selection listboxes only.
154
a660d684
KB
155\membersection{wxListBox::GetSelections}\label{wxlistboxgetselections}
156
605d715d 157\constfunc{int}{GetSelections}{\param{wxArrayInt\& }{selections}}
a660d684 158
fd9811b1 159Fill an array of ints with the positions of the currently selected items.
a660d684
KB
160
161\wxheading{Parameters}
162
fd9811b1 163\docparam{selections}{A reference to an wxArrayInt instance that is used to store the result of the query.}
a660d684
KB
164
165\wxheading{Return value}
166
167The number of selections.
168
169\wxheading{Remarks}
170
171Use this with a multiple selection listbox.
172
173\wxheading{See also}
174
bed5584e
VZ
175\helpref{wxControlWithItems::GetSelection}{wxcontrolwithitemsgetselection},\rtfsp
176\helpref{wxControlWithItems::GetStringSelection}{wxcontrolwithitemsgetstringselection},\rtfsp
177\helpref{wxControlWithItems::SetSelection}{wxcontrolwithitemssetselection}
a660d684 178
f899db6d
RD
179\pythonnote{The wxPython version of this method takes no parameters
180and returns a tuple of the selected items.}
181
2edb0bde 182\perlnote{In wxPerl this method takes no parameters and return the
5873607e
VZ
183selected items as a list.}
184
81108288
VZ
185\membersection{wxListBox::InsertItems}\label{wxlistboxinsertitems}
186
1a090517 187\func{void}{InsertItems}{\param{int}{ nItems}, \param{const wxString}{ *items}, \param{unsigned int}{ pos}}
81108288 188
1a090517 189\func{void}{InsertItems}{\param{const wxArrayString\&}{ nItems}, \param{unsigned int}{ pos}}
3980000c 190
81108288
VZ
191Insert the given number of strings before the specified position.
192
193\wxheading{Parameters}
194
195\docparam{nItems}{Number of items in the array {\it items}}
196
197\docparam{items}{Labels of items to be inserted}
198
199\docparam{pos}{Position before which to insert the items: for example, if {\it pos} is 0 the items
200will be inserted in the beginning of the listbox}
201
76e1c2de
RD
202\pythonnote{The first two parameters are collapsed into a single
203parameter for wxPython, which is a list of strings.}
204
5873607e
VZ
205\perlnote{In wxPerl there is just an array reference in place of {\tt nItems}
206and {\tt items}.}
207
c00fed0e
VZ
208\membersection{wxListBox::HitTest}\label{wxlistboxhittest}
209
210\constfunc{int}{HitTest}{\param{const wxPoint&}{ point}}
211
212Returns the item located at \arg{point}, or \texttt{wxNOT\_FOUND} if there
213is no item located at \arg{point}.
214
215\newsince{2.7.0}. It is currently implemented for wxMSW, wxMac and wxGTK2
216ports.
217
218\wxheading{Parameters}
219
220\docparam{point}{Point of item (in client coordinates) to obtain}
221
222\wxheading{Return value}
223
224Item located at \arg{point}, or \texttt{wxNOT\_FOUND} if unimplemented
225or the item does not exist.
226
4fb6c97e 227\membersection{wxListBox::IsSelected}\label{wxlistboxisselected}
a660d684 228
4fb6c97e 229\constfunc{bool}{IsSelected}{\param{int}{ n}}
a660d684
KB
230
231Determines whether an item is selected.
232
233\wxheading{Parameters}
234
235\docparam{n}{The zero-based item index.}
236
237\wxheading{Return value}
238
cc81d32f 239true if the given item is selected, false otherwise.
a660d684
KB
240
241\membersection{wxListBox::Set}\label{wxlistboxset}
242
2b5f62a0 243\func{void}{Set}{\param{int}{ n}, \param{const wxString*}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
a660d684 244
2b5f62a0
VZ
245\func{void}{Set}{\param{const wxArrayString\&}{ choices}, \param{void}{ **clientData = {\tt NULL}}}
246
247Clears the list box and adds the given strings to it.
a660d684
KB
248
249\wxheading{Parameters}
250
251\docparam{n}{The number of strings to set.}
252
253\docparam{choices}{An array of strings to set.}
254
2b5f62a0
VZ
255\docparam{clientData}{Options array of client data pointers}
256
a660d684
KB
257\wxheading{Remarks}
258
2b5f62a0
VZ
259You may free the array from the calling program after this function has been
260called.
a660d684 261
a660d684
KB
262\membersection{wxListBox::SetFirstItem}\label{wxlistboxsetfirstitem}
263
264\func{void}{SetFirstItem}{\param{int}{ n}}
265
266\func{void}{SetFirstItem}{\param{const wxString\& }{string}}
267
6a1fd44f 268Set the specified item to be the first visible item.
a660d684
KB
269
270\wxheading{Parameters}
271
272\docparam{n}{The zero-based item index.}
273
274\docparam{string}{The string that should be visible.}
275